背景
开发一款app,需要实现 长按微信接收的文件,可以选择使用我的app打开这个文件 这个功能
调研
使用插件
插件市场确实有现成的插件,传送门,不过也太贵了,799元对于我个人开发来说太贵了,所以决定自己实现这个功能
uniapp实现
通过2天的查找和实践,发现uniapp文档并没有这方面的介绍
实现方案
- 使用ai查询,说可以用intent方式实现,于是写demo,发现直接使用动态intent广播根本无法实现让我的应用出现在"使用其他应用打开"的列表中;
- 查询原生app实现方案,发现原生实现是在activity中增加intent-filter
- 下面是完整的AndroidManifest.xml内容
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:allowClearUserData="true"
android:largeHeap="true"
android:label="MD"
android:supportsRtl="true">
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|keyboard|navigation"
android:label="MD"
android:launchMode="singleTask"
android:hardwareAccelerated="true"
android:theme="@style/TranslucentTheme"
android:screenOrientation="user"
android:exported="true"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="io.dcloud.PandoraEntryActivity"
android:exported="true">
<!-- 接收分享 -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<!-- 将应用添加到其他应用打开列表 -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<!-- 需要根据实际修改 -->
<data android:mimeType="*/*"/>
<!-- 需要根据实际修改,这里是匹配.md结尾的文件 -->
<data android:pathPattern=".*\\.md"/>
<data android:scheme="content" />
</intent-filter>
</activity>
</application>
</manifest>
- 经过实践发现在uniapp的根目录下添加这个xml,然后进行打包后这个是有效的能够实现将应用显示在"使用其他应用打开"的列表中的效果
- 目录如下
注意 xml中的activity 的name是固定的,改了就错了;
添加好然后打包测试就可以实现将应用显示在"使用其他应用打开"的列表中
必须要打包后用真机测试,开发环境是不行的,至于如何实现数据传输,下一篇文章介绍