上篇文章录取的电话音频,这是用来读取播放方法
//path 文件路径
public void play(String path) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Log.e("TAG", path);
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
File file = new File(path);
if (!file.exists()){
Log.e("TAG","不存在");
return;
}
Uri photoURI = FileProvider.getUriForFile(this, getApplicationContext().getPackageName()+".provider" , file);
Log.e("TAG",photoURI.toString());
intent.setDataAndType(photoURI,"audio/*");
try {
startActivity(Intent.createChooser(intent,"录音"));
} catch (Exception e) {
e.printStackTrace();
}
//
}
//manifest文件配置
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.shiliu.callrecording.provider"//你的包名
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
//如果你依赖的第三方库中已经有了android.support.v4.content.FileProvider你可以自定义一个MyFileProvider继承FileProvider
eg:
<provider
android:name=".MyFileProvider"
android:authorities="com.shiliu.callrecording.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>