Reputation: 21
I'm looking for a way to customize my personal Alarm app and i want to choose when i want a different sound for my app browsing the sd audio files. the core of my code is this:
Button butsearch=(Button) findViewById(R.id.buttonsearch);
butsearch.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
mysearch.setAction(Intent.ACTION_GET_CONTENT);
mysearch.setType("audio/*");
startActivity(mysearch);
}
});
then android will display me a menu of app for browse the files, i usually choose Music(default) and a list will be displayed (i can listen a preview of the file too) but when i press the OK button i have to preserve the path of the file that i choose. I have to save it in a textview or similar and then in a database for use it in the alarm MediaPlayer.
i tryed startActivityForResult(mysearch, RESULT_OK);
but what i have to wrote in the body of the method? i tryed (just for see if it works)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Toast.makeText(getApplicationContext(), "result_notok", Toast.LENGTH_LONG).show();
if (resultCode == RESULT_OK)
{
Toast.makeText(getApplicationContext(), "result_ok", Toast.LENGTH_LONG).show();
}
}
but i can't see the toast.
Upvotes: 0
Views: 1036
Reputation: 735
Try this..
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_ALARM_OR_AUDIO_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
learn more about intent : intent ref.
Upvotes: 1