我有一个应用程序调用Android手机的默认相机拍照,以下是我的代码。
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
并且在onActivityResult方法中我正在执行以下操作
if ((requestCode == TAKE_PICTURE) && (resultCode == Activity.RESULT_OK)) {
Uri photoPath = intent.getData();
// do something with the uri here
}
以上代码在htc Tatto和索尼爱立信x10运行1.6上工作正常但在htc G1上运行1.6以上代码导致以下异常
03-08 18:54:25.906: ERROR/AndroidRuntime(4344): Uncaught handler: thread main exiting due to uncaught exception
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity removed
java.lang.NullPointerException
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.deliverResults(ActivityThread.java:3224)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3266)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.access$2600(ActivityThread.java:116)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.os.Looper.loop(Looper.java:123)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.main(ActivityThread.java:4203)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at java.lang.reflect.Method.invoke(Method.java:521)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at dalvik.system.NativeStart.main(Native Method)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): Caused by: java.lang.NullPointerException
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at removed
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.Activity.dispatchActivityResult(Activity.java:3624)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.deliverResults(ActivityThread.java:3220)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): ... 11 more
我已从例外
中删除了应用的包名称有关如何解决此问题的任何见解。谢谢。
答案 0 :(得分:7)
onActivityResult:
尝试使用:Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
答案 1 :(得分:0)