【发布时间】:2016-09-09 11:11:58
【问题描述】:
使用 intents.log cat 捕获 5 到 6 张照片后,我的应用程序崩溃了。我无法找到它崩溃的原因。请帮帮我。
private void capturePhoto() {
File root = new File(Environment.getExternalStorageDirectory(), "Feedback");
if (!root.exists()) {
root.mkdirs();
}
File file = new File(root, Constants.PROFILE_IMAGE_NAME + ".jpeg");
Uri outputFileUri = Uri.fromFile(file);
Intent photoPickerIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
photoPickerIntent.putExtra("return-data", true);
photoPickerIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(photoPickerIntent, requestCode);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (this.requestCode == requestCode && resultCode == RESULT_OK) {
File root = new File(Environment.getExternalStorageDirectory(), "Feedback");
if (!root.exists()) {
root.mkdirs();
}
File file = new File(root, Constants.PROFILE_IMAGE_NAME+".jpeg");
checkFlowIdisPresent(file);
displayPic();
}
}
private void displayPic() {
String filePath = Environment.getExternalStorageDirectory()
.getAbsolutePath() + File.separator + "/Feedback/" + Constants.PROFILE_IMAGE_NAME + ".jpeg";
// Bitmap bmp = BitmapFactory.decodeFile(filePath);
//Bitmap scaled = Bitmap.createScaledBitmap(bmp, 300, 300, true);
File imgFile = new File(filePath);
Bitmap bmp = decodeFile(imgFile);
if (imgFile.exists()) {
dispProfilePic.setImageBitmap(bmp);
} else {
dispProfilePic.setBackgroundResource(R.drawable.user_image);
}
}
private Bitmap decodeFile(File f) {
try {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f), null, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 70;
// Find the correct scale value. It should be the power of 2.
int scale = 1;
while (o.outWidth / scale / 2 >= REQUIRED_SIZE &&
o.outHeight / scale / 2 >= REQUIRED_SIZE) {
scale *= 2;
}
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {
}
return null;
}
以上代码用于拍摄照片并在 ImageView 中显示拍摄的图片。并且正在使用 MI 选项卡。
编辑实际上应用程序没有崩溃......它变成白屏,如果我按下任何按钮,它就会崩溃并且当它变成白屏时不会执行 onActivityResult
新编辑我能够复制这个。我点击了Android Monitor,因为我点击了Monitor。然后它显示我与应用程序交互时应用程序的内存利用率。现在在左侧栏中,我单击了终止应用程序图标。现在有趣的是它破坏了当前的活动并转移到以前的活动。之前的活动变成了白屏。
请帮帮我。
【问题讨论】:
-
您能发布崩溃日志吗?啊日志猫什么也没显示..
-
它什么也没显示。并且很难复制它
-
它必须显示一些东西。一旦您设法复制它,请在此处发布它,因为没有它,几乎不可能帮助您:/
-
您是否在清单文件中声明了权限,例如写入外部存储和摄像头
-
@NarenderReddy 没有权限它会在第一次崩溃
标签: android