I got my main Activity
which holds different Fragment
's, one fragment gives the user a possibility to open a DialogFragment
. That dialog opens a list of sound files and the dialog also contains a 'Add' button from which the user should be able to add her own soundfile. To do this I thought to use the standard Android file picking functionality and make use of the Intent.ACTION_GET_CONTENT
. So I fire away this intent when the user presses the 'Add' button and the Android file picking functionality comes up as it should, but when I choose a file, nothing happens what so ever. I would expect the onActivityResult()
of my main activity to be triggered but it doesn't, and I can't get it to work and I don't understand why this doesn't work.
public class MyDialog extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Rest omitted...
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(context)
.setIcon(android.R.drawable.ic_dialog_info)
.setTitle(R.string.TONE_PROMPT_TITLE)
.setNeutralButton(R.string.ADD, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("audio/mpeg");
getActivity().startActivityForResult(intent, ADD_SOUND_REQUEST_CODE);
}
})
.create();
}
}
I have also tried to instantiate the intent the following way:
Intent intent = new Intent(getActivity(), MyActivity.class);
but this doesn't work either.
Any ideas would be really helpful, thanks!