Skip to main content

Chose an Image file from android Storage 


dependencies{
       implementation 'com.karumi:dexter:6.2.3'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
}



floatingActionButton_attach.setOnClickListener(new View.OnClickListener() {
    @Override
public void onClick(View v) {
AlertDialog.Builder builder=new AlertDialog.Builder(getContext());

View view=LayoutInflater.from(getContext()).inflate(R.layout.alert_file_chose,null);
ImageView gallery=view.findViewById(R.id.gallery_id);
ImageView camera=view.findViewById(R.id.camera_id);

camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dexter.withContext(getContext()).withPermissions(
Manifest.permission.CAMERA
).withListener(new MultiplePermissionsListener() {
@Override public void onPermissionsChecked(MultiplePermissionsReport report) {

ContentValues contentValues=new ContentValues();
contentValues.put(MediaStore.Images.Media.TITLE,"ruhul pic");
contentValues.put(MediaStore.Images.Media.DESCRIPTION,"new pic");
imagaeuri=getContext().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);

Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,imagaeuri);
startActivityForResult(intent,CAMERA_CODE);

}
@Override public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
token.continuePermissionRequest();

}
}).check();
}
});

gallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


Dexter.withContext(getContext())
.withPermissions(
Manifest.permission.WRITE_EXTERNAL_STORAGE
).withListener(new MultiplePermissionsListener() {
@Override public void onPermissionsChecked(MultiplePermissionsReport report) {

Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent,REQUEST_GALLARY_CODE);

}
@Override public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
token.continuePermissionRequest();

}
}).check();

}
});

builder.setView(view);

builder.setNegativeButton("Cancil", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();

}
});

chose_alertDialog=builder.create();
chose_alertDialog.show();


}
});


@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode==RESULT_OK)
{
if (requestCode==CAMERA_CODE)
{
CropImage.activity(imagaeuri)
.setGuidelines(CropImageView.Guidelines.ON)
.start(getContext(),this);

}
if (requestCode==REQUEST_GALLARY_CODE)
{
CropImage.activity(data.getData())
.setGuidelines(CropImageView.Guidelines.ON)
.start(getContext(),this);

}

}



if (requestCode==CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)
{
CropImage.ActivityResult result = CropImage.getActivityResult(data);


if (resultCode == RESULT_OK) {



//alert dialog set spinner__________________

try {

chose_alertDialog.cancel();

}catch (Exception e)
{

}


androidx.appcompat.app.AlertDialog.Builder alertbuilder = new androidx.appcompat.app.AlertDialog.Builder(getContext());

LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.spinner_country_chose, null);


List<String> country_list=new ArrayList<>();
country_list.add("Africa");
country_list.add("Amharic");
country_list.add("Arabic");
country_list.add("Azerbaijani");
country_list.add("Bel");
country_list.add("Bengali");
country_list.add("Bosnian");
country_list.add("Bulgarian");
country_list.add("Catalan");
country_list.add("Cebuano");
country_list.add("Danish");
country_list.add("English");
country_list.add("Estonia");
//country_list.add("Philippines");
country_list.add("Fin");
//country_list.add("Gujarat");
country_list.add("Hebrew");
country_list.add("Hindi");
country_list.add("Indonesian");
country_list.add("Italian");
country_list.add("Urdu");

Spinner spinner = (Spinner)view. findViewById(R.id.action_bar_spinner_id);

ArrayAdapter adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,country_list);
spinner.setAdapter(adapter);
adapter.notifyDataSetChanged();
ImageView imageView=view.findViewById(R.id.imageurifileshow_id);

try {
Uri resultUri = result.getUri();
imageView.setImageURI(resultUri);
Log.e("imageurilocation",resultUri.toString());
BitmapDrawable bitmapDrawable= (BitmapDrawable) imageView.getDrawable();
bitmap=bitmapDrawable.getBitmap();

}catch (Exception e)
{

}


spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

languageposition=position;
adapter_select_language=parent.getItemAtPosition(position).toString();

Snackbar.make(getView(),"[sellect : ]"+adapter_select_language,Snackbar.LENGTH_SHORT);


}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});

alertbuilder.setView(view);


alertbuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id)
{


if (languageposition==-1)
{
Toast.makeText(getContext(), "Please sellect language...", Toast.LENGTH_SHORT).show();
}
else {


try {
copy.execute();
ocr.execute();

}catch (Exception e)
{
Toast.makeText(getContext(), "[error] : "+e.getMessage().toString(), Toast.LENGTH_SHORT).show();

}



}



}
});
alertbuilder.setNegativeButton("cancil", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}
});

androidx.appcompat.app.AlertDialog alertDialog = alertbuilder.create();
alertDialog.show();








}


}
}


bitmap convert to String data : like

public String BitMapToString(Bitmap bitmap){
     ByteArrayOutputStream baos=new  ByteArrayOutputStream();
     bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
     byte [] b=baos.toByteArray();
     String temp=Base64.encodeToString(b, Base64.DEFAULT);
     return temp;
}





Comments

Popular posts from this blog

 var val  deference in kotlin  fun main () { var Android_Programing_language : String = "java" println ( "android official programing language: " + Android_Programing_language ) Android_Programing_language = "Kotline" println ( "2019 google announced android official programing language: " + Android_Programing_language ) val Android_MultiPlatform_language : String = "Dart" println ( "multiple device run : " + Android_MultiPlatform_language ) /* Android_MultiPlatform_language="" /* note: var--------------valu changable note: val--------------valu not changable (final) */ */ }
 Firebase Cloud Messaging With  push notification with Image  public class ImageDownload extends AsyncTask < String , Void , Bitmap >{ @Override protected Bitmap doInBackground ( String ... strings ) { InputStream inputStream ; try { URL url = new URL( strings [ 0 ]) ; try { HttpURLConnection connection = ( HttpURLConnection ) url .openConnection() ; connection .connect() ; inputStream = connection .getInputStream() ; return BitmapFactory . decodeStream ( inputStream ) ; } catch ( IOException e ) { e .printStackTrace() ; } } catch ( MalformedURLException e ) { e .printStackTrace() ; } return null; } @Override protected void onPostExecute ( Bitmap bitmap ) { ShowNotification( bitmap ) ; } }
AppBar ViewPager with  Tab layout in android  XML : <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" xmlns: app ="http://schemas.android.com/apk/res-auto" android :id ="@+id/mainrelative_layout_id" android :background ="@color/colorPrimary" android :theme ="@style/Appthemnoactionbar" android :layout_height ="match_parent" tools :context ="com.ruhul.scanner.Fragment_Activity.ListFragment" > <com.google.android.material.appbar.AppBarLayout android :id ="@+id/tablayoutid" android :layout_width ="match_parent" android :background ="@color/colorPrimary" android :layout_height ="?actionBarSize" > ...