by hitting on allow throws me:
- 1.- There are devices that send me Superposition of the screen, which I do not want. How to solve this?
-
2 .- In other devices Samsung definitely closed when you open camera, Eye! I can not debug this because the test cell phones do not have them.
private static String APP_DIRECTORY = "MyPictureApp/"; private static String MEDIA_DIRECTORY = APP_DIRECTORY + "PictureApp"; private final int MY_PERMISSIONS = 100; private final int PHOTO_CODE = 200; private final int SELECT_PICTURE = 300; private String mPath;
Button to open a dialog Camera / Gallery
if(mayRequestStoragePermission()){ seleccionarMedio(); }
We select which half will be Gallery / Camera
private void seleccionarMedio() {
LayoutInflater inflater = LayoutInflater.from(this);
//vista que contiene el diseño
View login_layout = inflater.inflate(R.layout.vista_foto,null);
//botones de seleccion de tipo de captura
LinearLayout Galeria = (LinearLayout)login_layout.findViewById(R.id.botonGaleria);
LinearLayout Tomar = (LinearLayout)login_layout.findViewById(R.id.botonTomar);
//Creacion de AlertDialog
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Selecciona una foto");
alertDialog.setMessage("Puedes tomar una foto o cargar una antes previamente tomada");
alertDialog.setView(login_layout);
//Botones dentro del alertDialog
final AlertDialog show = alertDialog.show();
Galeria.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent.createChooser(intent, "Selecciona app de imagen"), SELECT_PICTURE);
//Cerrar dialogo para evitar que se mantenga una ves tomada la foto
show.dismiss();
}
});
Tomar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//openCamera();
if (ContextCompat.checkSelfPermission(Reporte_App.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(Reporte_App.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(Reporte_App.this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 110);
} else {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 22);
}
show.dismiss();
}
});
}
Result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
BitmapFactory.Options opts = new BitmapFactory.Options ();
opts.inSampleSize = 2; // for 1/2 the image to be loaded
if(resultCode == RESULT_OK){
switch (requestCode){
case PHOTO_CODE:
MediaScannerConnection.scanFile(this,
new String[]{mPath}, null,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> Uri = " + uri);
}
});
Bitmap bitmap = BitmapFactory.decodeFile(mPath);
Fotografia.setImageBitmap(bitmap);
Imagen =((BitmapDrawable) Fotografia.getDrawable()).getBitmap();
verificadores[1].setText("Listo (Capturada)");
break;
case SELECT_PICTURE:
Uri path = data.getData();
Fotografia.setImageURI(path);
Imagen =((BitmapDrawable) Fotografia.getDrawable()).getBitmap();
verificadores[1].setText("Listo (De Galeria)");
break;
}
}
}
PermissionResult
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == MY_PERMISSIONS){
if(grantResults.length == 2 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED){
Toast.makeText(Reporte_App.this, "Permisos aceptados", Toast.LENGTH_SHORT).show();
}
}else{
showExplanation();
}
}
Warning message
private void showExplanation() {
AlertDialog.Builder builder = new AlertDialog.Builder(Reporte_App.this);
builder.setTitle("Permisos denegados");
builder.setMessage("Para usar las funciones de la app necesitas aceptar los permisos");
builder.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
});
builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
builder.show();
}
Possible error? I would like you to keep an eye on the part of the permits and see if everything is stated correctly. I await your help.
Trying manually Apparently the whole problem comes from here.
Update ERROR!
E/AndroidRuntime: FATAL EXCEPTION: main
Process: desarrolladoresalpha.tocumbomovil, PID: 2654
android.os.FileUriExposedException: file:///storage/emulated/0/MyPictureApp/PictureApp/1516757788.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:845)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8941)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8926)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
at android.app.Activity.startActivityForResult(Activity.java:4225)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:4183)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at desarrolladoresalpha.tocumbomovil.App_Reportes.Reporte_App.openCamera(Reporte_App.java:276)
at desarrolladoresalpha.tocumbomovil.App_Reportes.Reporte_App.access$200(Reporte_App.java:77)
at desarrolladoresalpha.tocumbomovil.App_Reportes.Reporte_App$9.onClick(Reporte_App.java:322)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)