誰かが私を助けてくれますか。 私は写真を撮ることができ、ギャラリーに表示されますが、イメージビューでは設定できません。アプリがクラッシュします。 マイコードカメラインテントアプリクラッシュ
多分何かがactivityresultに間違っていますか?
File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "LetsTalk_img" + timeStamp;
File storageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName,".jpg", storageDirectory);
mImageFileLocation = image.getAbsolutePath();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(image)));
return image;
}
とonactivityresult: はここで私のミスです
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException e) {
e.printStackTrace();
}
String authorities = getApplicationContext().getPackageName() + ".fileprovider";
Uri imageUri = FileProvider.getUriForFile(camtest.this, authorities, photoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
if (photoFile != null) {
imageUri = FileProvider.getUriForFile(camtest.this,
BuildConfig.APPLICATION_ID + ".fileprovider",
photoFile);
Log.i("Uri", imageUri.toString());
// takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
}
else{
Log.i("Uri", "none");
}
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(photoFile)));
startActivityForResult(intent, 7);
}
});
ファイルメソッドを作成?事前
方法:スタックトレース? – Alessio
onClick()でメディアスキャナを呼び出さないでください。早くまで。ユーザーは写真を撮らないことも決めることができます。 mediascannerコードをonActivityResult()に移動します。 – greenapps
onActivityResultでビットマップを取得しようとしました。しかし、EXTRA_OUTPUTを使用するときは、1つを取得しません。 – greenapps