Après avoir mis à jour le code pour inclure Fileprovider pour l'API 24 et supérieur, j'obtiens l'erreur "La galerie continue de s'arrêter". Ci-dessous est le segment de code pour capturer l'image de la caméra et effectuer le recadrage et l'enregistrer.Erreur d'arrêt de la galerie, après avoir inclus Fileprovider pour l'API 24 et supérieure
Lorsque j'ai tracé le code, il s'exécute jusqu'à startActivityForResult (cropIntent, 3) dans performcrop() puis donne l'erreur ci-dessus. (Note: il n'y a pas beaucoup d'informations dans la sauvegarde d'erreurs, testé sur Nexus 7.0).
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == 2)
{
Bundle extras = data.getExtras();
Bitmap var_Bitmap = (Bitmap) extras.get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
var_Bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bytes = stream.toByteArray();
try {
OutputStream out;
String root = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
File createDir = new File(root+"master"+File.separator);
createDir.mkdir();
File file = new File(root + "master" + File.separator +"master.jpg");
file.createNewFile();
out = new FileOutputStream(file);
out.write(bytes);
out.close();
path1=root + "master" + File.separator +"master.jpg";
//imageUri= Uri.fromFile(file);
if (Build.VERSION.SDK_INT > 23)
imageUri = FileProvider.getUriForFile(RecognizeActivity.this,
BuildConfig.APPLICATION_ID + ".provider",
file);
else
imageUri= Uri.fromFile(file);
} catch (IOException e) {
// e.printStackTrace();
}
performCrop();
} else if (requestCode==3)
{
Bundle extras = data.getExtras();
Bitmap var_Bitmap = (Bitmap) extras.get("data");
ImageView imageView1 = (ImageView) findViewById(R.id.ui_imageView_browse);
imageView1.setImageBitmap(var_Bitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
var_Bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bytes = stream.toByteArray();
try {
OutputStream out;
String root = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
File createDir = new File(root+"master"+File.separator);
createDir.mkdir();
File file = new File(root + "master" + File.separator +"master.jpg");
file.createNewFile();
out = new FileOutputStream(file);
out.write(bytes);
out.close();
path1=root + "master" + File.separator +"master.jpg";
} catch (IOException e) {
// e.printStackTrace();
}
ImageView imageView_error = (ImageView) findViewById(R.id.ui_imageView_error);
imageView_error.setVisibility(View.VISIBLE);
imageView_error.setImageResource(R.drawable.process);
userupdate();
if(netcheck==0)
{
FeedTask ft = new FeedTask();
ft.execute(path1);
}
}
}
public void performCrop() {
// take care of exceptions
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(imageUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "false");
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 0);
cropIntent.putExtra("aspectY", 0);
// indicate output X and Y
cropIntent.putExtra("outputX", 300);
cropIntent.putExtra("outputY", 300);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent,3);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
Toast toast = Toast
.makeText(this, "This device doesn't support the crop action!", Toast.LENGTH_SHORT);
toast.show();
}
}
utiliser 'data.getUri()' –