需要用到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;
}
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/*
转载于:https://blog.51cto.com/2960629/723493