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) */ */ }
 phone authentication in android using Firebase Step 1:    Add Firebase to your Android project Step 2: Add this line build.Gradle(project) // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath "com.android.tools.build:gradle:4.1.1" classpath 'com.google.gms:google-services:4.3.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean( type : Delete) { delete rootProject . buildDir } Step 3: Add this dependency build.Gradle (app level) plugins { id 'com.android.application' } android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.ruhul.firebasephone...
  Android  Location Permissions With  GPS  disabled Enable Hello Everyone, In this Tutorial I Will Show you how Can I Get Android Location Permission Granted. In Case There is a Common Problemes When User Allow Permission Granted but not Gps Enable. So how Can I Solve This Problemes Flow this Step Step 1: AndroidManifest.xml  file  Permission add <uses-permission android :name ="android.permission.INTERNET" /> <uses-permission android :name ="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android :name ="android.permission.ACCESS_BACKGROUND_LOCATION" /> Step 2: Android XML Design Simple Button like  <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_pa...