我已经在Android Studio上工作了一年(我是新手呵呵),但从未遇到过这个问题。
当我拍照并按“确定”按钮时,相机崩溃且日志未提供清晰的信息,因此不会调用onActivityResult。 这仅在Android 8.0(华为P8)和9.0(Pixel 3XL)中发生,而在Android 8.0(Moto e5)或Android 7.1.2(小米Redmi 4A)中则没有。
相机意图
private void cameraIntent() {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case CAMERA:
placeholder.setVisibility(View.GONE);
bitmapImg = (Bitmap) data.getExtras().get("data");
bitmapImg = scaleDown(bitmapImg, 800, true);
imageExist = true;
imageView.setImageBitmap(bitmapImg);
menu.findItem(R.id.rotate_photo_gallery).setVisible(true);
break;
}
}
}
崩溃日志
--------- beginning of crash
2019-04-12 15:54:47.444 28783-28783/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.android.GoogleCamera, PID: 28783
java.lang.NullPointerException
at oag.b(PG:232)
at nre.b(PG:1)
at ekm.e(PG:5)
at ekm.c(PG:37)
at czm.b(PG:13)
at czm.a(PG:33)
at egn.onShutterButtonClick(PG:9)
at jry.onShutterButtonClick(PG:16)
at com.google.android.apps.camera.ui.shutterbutton.ShutterButton.performClick(PG:498)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-04-12 15:54:47.450 1165-2517/? W/ActivityManager: Force finishing activity com.google.android.GoogleCamera/com.android.camera.activity.CaptureActivity
2019-04-12 15:54:47.453 28783-28783/? I/Process: Sending signal. PID: 28783 SIG: 9
2019-04-12 15:54:47.471 1165-1179/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
2019-04-12 15:54:47.471 1165-1179/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
2019-04-12 15:54:47.474 1165-1181/? I/ActivityManager: Start proc 28990:com.google.android.GoogleCamera:crash_report/u0a112 for service com.google.android.GoogleCamera/com.google.android.apps.camera.app.silentfeedback.SilentFeedbackService
2019-04-12 15:54:47.480 1165-1353/? W/InputDispatcher: channel '6ea5f67 com.google.android.GoogleCamera/com.android.camera.activity.CaptureActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2019-04-12 15:54:47.481 1165-1353/? E/InputDispatcher: channel '6ea5f67 com.google.android.GoogleCamera/com.android.camera.activity.CaptureActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-04-12 15:54:47.488 28990-28990/? E/ra:crash_repor: Not starting debugger since process cannot load the jdwp agent.
答案 0 :(得分:1)
我遇到了完全相同的问题。此问题是由内存泄漏引起的,可以通过在相机意图中传递Uri而不是访问内存中的位图来解决。我在另一个线程Android crashing after camera Intent
上遵循了建议