uniapp 实现将应用显示在“使用其他应用打开“的列表中

该文章已生成可运行项目,

背景

开发一款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是固定的,改了就错了;
    添加好然后打包测试就可以实现将应用显示在"使用其他应用打开"的列表中
    必须要打包后用真机测试,开发环境是不行的,至于如何实现数据传输,下一篇文章介绍
本文章已经生成可运行项目
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值