简体   繁体   中英

Android Get Image Uri from Camera

I have an application that calls the android phone's default camera to take photo the following is my code.

                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, TAKE_PICTURE);

and in the onActivityResult method I am doing the following

        if ((requestCode == TAKE_PICTURE) && (resultCode == Activity.RESULT_OK)) {
        Uri photoPath = intent.getData();
                    // do something with the uri here
            }

The above code works fine on htc Tatto and Sony ericsson's x10 running 1.6 but in on htc G1 running 1.6 the above code causes the following exception

        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

I have removed the app's package name from the exception

Any insights into how to solve this problem. Thank you.

onActivityResult:

Try to use: Bitmap thumbnail = (Bitmap) data.getExtras().get("data");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM