0

I'm creating two class to work with image in android. The first class will trigger startActivityForResult to open camera app then create a folder and and image file if it is doesn't exist. My problem is I want to pass the created path to my main class which have onActivityResult method. Here is my code that trigger startActivityForResult and this is my class that hold onActivityResult

I will appreciate any help. Thank you.

Raditya Kurnianto
  • 734
  • 1
  • 16
  • 42
  • Use Shared Preferences also you can Use Application Context. See [this](http://stackoverflow.com/questions/920306/sending-data-back-to-the-main-activity-in-android) – MrDumb Oct 16 '14 at 12:38

1 Answers1

0

In the onActivityResult you have intent data, thats what the camera app sends back to your activity.

That being said, data.getData() will give you the path the image was stored in.

Documentation here: http://developer.android.com/guide/topics/media/camera.html#intents

  • In response to your answer I've edited my code so it look like this on `onActivityResult` `String path = data.getStringExtra("PATH"); Toast.makeText(getApplicationContext(), path, Toast.LENGTH_LONG).show();` and I also change my `startActivityForResult` to `cameraIntent.putExtra("PATH", photoFile.getAbsolutePath());` I got null pointer on `data.getStringExtras("PATH");` – Raditya Kurnianto Oct 16 '14 at 12:55
  • The intent you get in onActivityResult is not the same as the one you send in the startActivityForResult which means any extras can be lost depending on the package that handles the sent intent. In any case data.getData() should return the path uri. –  Oct 16 '14 at 12:57
  • Fyi, I have passed the context or activity that send the trigger in `startActivityForResult` .So what is you best suggestion? – Raditya Kurnianto Oct 16 '14 at 13:07
  • Try this on your onaCtivityResult method: Log.d("data", data.getData().toString()); Then report back with the output :) –  Oct 16 '14 at 13:13
  • the result return null – Raditya Kurnianto Oct 16 '14 at 13:28
  • I am using a similar implementation in one of my apps and it works. However i did some research in this issue (as it could possibly affect my own application) and discovered that some devices do return a null URI while others don't. Means that you will have to save the path you create to sharedPreferences. –  Oct 16 '14 at 13:55