Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Image path from camera intent

Tags:

There is option of capture image from camera in my application.But there is problem to get image from camera. When i use ACTION_IMAGE_CAPTURE this it return null data.Please help me get image path from camera intent

Error Log:

07-04 11:22:36.902: E/AndroidRuntime(8329): FATAL EXCEPTION: main
07-04 11:22:36.902: E/AndroidRuntime(8329): java.lang.RuntimeException: Unable to resume activity {com.pausefablogin/com.pausefablogin.AddPOI}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=null} to activity {com.pausefablogin/com.pausefablogin.AddPOI}: java.lang.NullPointerException
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2124)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.access$1600(ActivityThread.java:117)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.os.Looper.loop(Looper.java:130)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.main(ActivityThread.java:3687)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at java.lang.reflect.Method.invokeNative(Native Method)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at java.lang.reflect.Method.invoke(Method.java:507)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at dalvik.system.NativeStart.main(Native Method)
07-04 11:22:36.902: E/AndroidRuntime(8329): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=null} to activity {com.pausefablogin/com.pausefablogin.AddPOI}: java.lang.NullPointerException
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2111)
07-04 11:22:36.902: E/AndroidRuntime(8329):     ... 13 more
07-04 11:22:36.902: E/AndroidRuntime(8329): Caused by: java.lang.NullPointerException
07-04 11:22:36.902: E/AndroidRuntime(8329):     at com.pausefablogin.AddPOI.onActivityResult(AddPOI.java:281)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
07-04 11:22:36.902: E/AndroidRuntime(8329):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
07-04 11:22:36.902: E/AndroidRuntime(8329):     ... 14 more

Thanks in advance

like image 431
Amit Sharma Avatar asked Jul 04 '13 05:07

Amit Sharma


1 Answers

try this one

 Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(i , 0);          

and call this

@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent resultData) {
    super.onActivityResult(requestCode, resultCode, resultData);

        if (resultData != null) {

        String[] projection = { MediaStore.Images.Media.DATA };
                Cursor cursor = managedQuery(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        projection, null, null, null);
                int column_index_data = cursor
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToLast();

                String imagePath = cursor.getString(column_index_data);
                Bitmap bitmapImage = BitmapFactory.decodeFile(imagePath );
                imageView.setImageBitmap(bitmapImage );

            }

and use the prrmission what you want

 <uses-permission android:name="android.permission.CAMERA" /> 
    <permission android:name="android.permission.FLASHLIGHT" />
    <uses-feature android:name="android.hardware.camera"/>
like image 183
Sunil Kumar Avatar answered Sep 20 '22 02:09

Sunil Kumar