Select folder intent & Work out when intent complete?
So I'm making a wallpaper and I want the user to select a folder. So I have a button in the preferences that launches an intent to open an image, but what I want is actually just a directory (I guess in the worst case开发者_如何学Go i can strip the filename from the end). So that's my first problem: what's the best way to select a folder only?
The second problem is how do I get notified of when the intent is complete?
public class FilePreference extends DialogPreference implements
View.OnClickListener
{
public void onClick(View v)
{
// open up a gallery/file browser
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
getContext().startActivity(Intent.createChooser(intent, "Select Folder"));
}
use Activity.startActivityForResult
and override Activity.onActivityResult
Okay that helped a bit, I managed to work out my wallpaper service was actually an activity. SO then I had to find my preference by name and add a pointer to it so the preference could use startActivityForResult and onActivityResult
精彩评论