Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在意图搜索中获取音频文件的路径_Android_Search_Audio_Path_Android Intent - Fatal编程技术网

Android 在意图搜索中获取音频文件的路径

Android 在意图搜索中获取音频文件的路径,android,search,audio,path,android-intent,Android,Search,Audio,Path,Android Intent,我正在寻找一种方法来定制我的个人闹钟应用程序,我想选择什么时候我想为我的应用程序浏览sd音频文件时使用不同的声音。 我的代码的核心是: Button butsearch=(Button) findViewById(R.id.buttonsearch); butsearch.setOnClickListener(new OnClickListener() { public void onClick(View v) { myse

我正在寻找一种方法来定制我的个人闹钟应用程序,我想选择什么时候我想为我的应用程序浏览sd音频文件时使用不同的声音。 我的代码的核心是:

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);
        }
    });
然后安卓会给我显示一个浏览文件的应用程序菜单,我通常选择音乐(默认),然后会显示一个列表(我也可以收听文件预览),但当我按下OK按钮时,我必须保留我选择的文件路径。我必须将其保存在textview或类似的文件中,然后保存在数据库中,以便在alarm MediaPlayer中使用

我尝试了startActivityForResult(我的搜索,结果正常)

但是我必须在方法的主体中写些什么呢? 我尝试过(只是为了看看它是否有效)

但是我看不到烤面包片。

试试这个

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);

了解有关意图的更多信息:

使用startActivityForResult(而不是startActivity)

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);