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是固定的,改了就错了;
    添加好然后打包测试就可以实现将应用显示在"使用其他应用打开"的列表中
    必须要打包后用真机测试,开发环境是不行的,至于如何实现数据传输,下一篇文章介绍
UniApp实现定位功能,首先你需要引入相关的插件。UniApp 提供了 Geolocation API 来获取用户的地理位置信息。以下是基本步骤: 1. **安装插件**: 打开项目管理器(uni-app官网上有详细的文档),搜索 "geolocation" 或者 "位置" 插件,并按照提示安装。 2. **权限请求**: 在 App.vue 文件或其他需要定位的地方,添加权限请求代码,例如: ```javascript import { getLocation } from '@vant/geolocation'; getLocation({ type: 'wgs84', // 请求的坐标类型,默认为wgs84 enableHighAccuracy: true, // 是否允许高精度定位,默认为true timeout: 10000, // 设置超时时间,单位为毫秒,默认为10秒 success(res) { console.log('定位成功:', res); // 在这里处理定位结果 }, error(err) { console.error('定位失败:', err); } }); ``` 3. **监听位置变化**: 如果你想实时更新用户的位置并在地图上显示,可以设置周期性的位置刷新,如每5秒更新一次: ```javascript setInterval(() => { getLocation(); }, 5000); ``` 4. **地图组件集成**: 使用 UniMap 组件,你可以将定位结果显示在地图上。确保已经导入了 `@mapbox/mapbox-gl` 和 `@vue-mapbox-gl/core` 等依赖。然后,在地图上添加marker到用户当前位置: ```javascript import MapView from '@vue-mapbox-gl/core'; import Marker from '@vue-mapbox-gl/components/marker'; <MapView :center="currentLocation" :zoom="14"> <Marker :latLng="currentLocation" /> </MapView> ``` 记得替换 `currentLocation` 为你从定位服务获取的实际经纬度数据。 5. **初始化位置信息** (如果首次运行应用): 首次启动应用时,可能会因没有GPS信号而无法立即获取位置,此时可以在适当的地方尝试获取位置信息。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值