Intent打开各种类型的文件
16lz
2021-01-23
需要用到Intent.setDataAndType(path,type)函数 模板: //android获取一个用于打开PPT文件的intent
public static Intent getPptFileIntent( String param )
{
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param ));
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
return intent;
}
打开不同类型的文件只需要修改参数type即可: 打开APK——application/vnd.android.package-archive 打开PPT——application/vnd.ms-powerpoint 打开Excel——application/vnd.ms-excel 打开Word——application/msword 打开CHM——application/x-chm 打开文本txt——text/plain 打开PDF——application/pdf 打开VCF——text/x-vcard 打开SWF——flash/*
public static Intent getPptFileIntent( String param )
{
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param ));
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
return intent;
}
打开不同类型的文件只需要修改参数type即可: 打开APK——application/vnd.android.package-archive 打开PPT——application/vnd.ms-powerpoint 打开Excel——application/vnd.ms-excel 打开Word——application/msword 打开CHM——application/x-chm 打开文本txt——text/plain 打开PDF——application/pdf 打开VCF——text/x-vcard 打开SWF——flash/*
更多相关文章
- android studio恢复误删文件
- Android SD 卡文件浏览器
- android canvas中translate函数的使用
- Android 获取文件的缩略图
- Android 文件相关总结
- android私有文件资源文件的存取
- Android调用系统自带的文件管理器进行文件选择
- Android判断有无外置SD卡(TF卡),并读写文件