Question

So, what I'm actually looking for is this solution: Get/pick an image from Android's built-in Gallery app programmatically but working in a preference and not in an activity.

I created a class that I put in my setting and I want to use that class to be able to find the URI of an image selected by the user on its phone. I couldn't use the code in that link because of "startActivityForResult". Which is not available in a preference.

Any idea how to bypass this ?

PROGRESS REPORT:

So, I tried some stuff in the mean time. Instead, in my settings, I added the following:

 <Preference
    android:key="test"
    android:title="open image"
    android:persistent="true">

    <intent android:action="android.intent.action.GET_CONTENT"
            android:value="image/*"/>

 </Preference>

First, instead of "GET_CONTENT", it was "PICK", but with it, I can only go with Google Docs and the Sim Card Tool Kit, which is far from the gallery or any thing to browse the file system.

With "GET_CONTENT", it crashes.

I also added the "android.permission.WRITE_EXTERNAL_STORAGE" premission, even if I just want to read. But I didn't found any (let put this as a sub question, if there's a way to just ask to read and not write).

PROGRESS REPORT #2

I replaced android:value by android:mimeType and I goes directly to the gallery. Now, just need to know if I really got the URI and it's solved.

PROGRESS REPORT #3

At this point, here's the real problem. When I go through my SharedPreferences, the value stays empty, even after selecting an images. So, I guess there a little hack to do. So now, that's the question. Based on the example of my preference screen above, how can I retrieve the value of "test", assuming that when the intent is called, it put it somewhere ?

Was it helpful?

Solution

I finally found a solution... it's not as feng shui as I would like, but it works.

I simply code the preference screen by hand and then I was able to access the "startActivityForResult" function.

From this point, it took 3 to 5 minutes to solve it and finalize all the details.

Hope it helps some people.

You have an example there: http://www.anddev.org/code-snippets-for-android-f33/preference-screen-with-custom-views-t8472.html

But the one I used was on google, but I couldn't find the link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top