Here is my problem: I need to save the photo to the default folder, and not copy it to my personal place, add GPS tags for copying and delete the original photo. Why so around? Because on some devices when using MediaStore.EXTRA_OUTPUT in the request, the target image was saved anywhere by default. Now that the application was almost complete, when testing on a new device (Motorola MB526), โโit is crushed after taking the picture. The same thing happens on the emulator.
The fact is that onActivityResult(int requestCode, int resultCode, Intent data) data.getData() returns null.
So my question is: is there any unified way to save the image in this place and nowhere?
EDIT:
capture image intent
protected void takePhotos() { Intent imageIntent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(imageIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); }
and result
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK && data != null) { Uri capturedImageUri = data.getData(); Log.d("cameraResult", "data =" + data.getDataString()); String capturedPicFilePath = getRealPathFromURI(capturedImageUri); writeImageData(capturedImageUri, capturedPicFilePath); } else if (resultCode == RESULT_CANCELED) { Toast.makeText(this, "Picture not taken", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Picture not taken", Toast.LENGTH_SHORT).show(); } } } } public String getRealPathFromURI(Uri contentUri) { String[] projx = { MediaStore.Images.Media.DATA }; Cursor cursor; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { CursorLoader loader = new CursorLoader(this, contentUri, projx, null, null, null); cursor = loader.loadInBackground(); } else { cursor = this.managedQuery(contentUri, projx, null, null, null); } int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
logCat output:
07-23 18:42:26.486: D/cameraResult(1744): data =null 07-23 18:42:26.486: D/AndroidRuntime(1744): Shutting down VM 07-23 18:42:26.486: W/dalvikvm(1744): threadid=1: thread exiting with uncaught exception (group=0xb70334f0) 07-23 18:42:26.496: E/AndroidRuntime(1744): FATAL EXCEPTION: main 07-23 18:42:26.496: E/AndroidRuntime(1744): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1513, result=-1, data=Intent { act=inline-data (has extras) }} to activity {arios.e_gps/arios.e_gps.photos.PhotoListAct}: java.lang.NullPointerException 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.app.ActivityThread.access$2000(ActivityThread.java:117) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.os.Handler.dispatchMessage(Handler.java:99) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.os.Looper.loop(Looper.java:130) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.app.ActivityThread.main(ActivityThread.java:3683) 07-23 18:42:26.496: E/AndroidRuntime(1744): at java.lang.reflect.Method.invokeNative(Native Method) 07-23 18:42:26.496: E/AndroidRuntime(1744): at java.lang.reflect.Method.invoke(Method.java:507) 07-23 18:42:26.496: E/AndroidRuntime(1744): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 07-23 18:42:26.496: E/AndroidRuntime(1744): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-23 18:42:26.496: E/AndroidRuntime(1744): at dalvik.system.NativeStart.main(Native Method) 07-23 18:42:26.496: E/AndroidRuntime(1744): Caused by: java.lang.NullPointerException 07-23 18:42:26.496: E/AndroidRuntime(1744): at arios.e_gps.photos.PhotoListAct.getRealPathFromURI(PhotoListAct.java:316) 07-23 18:42:26.496: E/AndroidRuntime(1744): at arios.e_gps.photos.PhotoListAct.onActivityResult(PhotoListAct.java:165) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.app.Activity.dispatchActivityResult(Activity.java:3908) 07-23 18:42:26.496: E/AndroidRuntime(1744): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528) 07-23 18:42:26.496: E/AndroidRuntime(1744): ... 11 more