最近有个需求,需要在app中显示ppt,第一反应就是从文件管理中选择ppt,然后用第三方控件显示,结果ios开发人员跟我说在ios上可以直接选择打开方式,比如微信接收到一个ppt,然后选择打开,会弹出一个列表,可以选择自己的app打开。当时我就觉得很好奇了,然后我也试验了下,发现除了offic软件,百度网盘也在列表中,那么说明是可以设置的。果不其然,在网上一番搜索后,找到
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
补充:
如果需要设置多个类型,又不想设置成全类型,只需要多写几个mineType就可以了,比如我项目中只允许ppt、pptx、pdf类型的文件,只需要如下设置即可
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
<data android:mimeType="application/vnd.ms-powerpoint"/>
</intent-filter>
再补充个从APP中去选择本地文件的方法,同样是允许三个类型的文件
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent .setType("*/*");
String[] mimeTypes = {"application/vnd.ms-powerpoint", "application/pdf","application/vnd.openxmlformats-officedocument.presentationml.presentation"};
intent .putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, INTENT_FILE);
但是我有个问题,要是有知道的