Android Get Image Uri from Camera

Posted by josnidhin on Stack Overflow See other posts from Stack Overflow or by josnidhin
Published on 2010-03-08T10:59:22Z Indexed on 2010/03/08 11:06 UTC
Read the original article Hit count: 859

Filed under:

Hi

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

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

© Stack Overflow or respective owner

Related posts about android