如彩信、Email、Gmail、网站等添加附件,如果应用本身没有做文件浏览选择的功能,此时应用可以通过发送ACTION_GET_CONTENT的系统接口来获取其他具备浏览选择文件功能的应用来支持该功能,比如此时添加附件会弹出一个选择框,有图库、音乐播放器等,现在如果想让FM也支持,在AndroidMenifest.xml中添加如下配置:
<intent-filter>
<action andriod:name="android.intent.action.GET_CONTENT"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimetype="*/*"/>
</intent-filter>
在点击Item打开File的时候添加如下代码:
String action=mContext.getIntent().getAction();
if(!TextUtils.isEmpty(action)&&action.equals(Intent.ACTION_GET_CONTENT)){
Uri uri=getDbUriFromFilepath(mContext,filepath);
//从数据库中查询该物理路径对应的Uri
if(uri!=null){
intent.setDataAndType(uri,type);
}else{
intent.setDataAndType(Uri.fromFile(new File(filepath)),type);
}
mContext.setResult(Activity.RESULT_OK,intent);
mContext.finish();
return;
}
<intent-filter>
<action andriod:name="android.intent.action.GET_CONTENT"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimetype="*/*"/>
</intent-filter>
在点击Item打开File的时候添加如下代码:
String action=mContext.getIntent().getAction();
if(!TextUtils.isEmpty(action)&&action.equals(Intent.ACTION_GET_CONTENT)){
Uri uri=getDbUriFromFilepath(mContext,filepath);
//从数据库中查询该物理路径对应的Uri
if(uri!=null){
intent.setDataAndType(uri,type);
}else{
intent.setDataAndType(Uri.fromFile(new File(filepath)),type);
}
mContext.setResult(Activity.RESULT_OK,intent);
mContext.finish();
return;
}