You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在React Native/Expo安卓应用中打开已安装的自研APK

问题解答

完全可以在无需联网、无需跳转谷歌Play商店的前提下实现该需求,核心原理是安卓系统支持通过包名和指定Activity的Intent唤起已安装的第三方应用,具体实现方案分场景说明:

一、前置准备

你需要提前拿到自研APK的两个核心信息:

  • 应用的包名(示例格式:com.yourcompany.selfdeveloped.app)
  • 要唤起的入口Activity全路径(如果是默认启动页一般为包名.MainActivity,也可以在自研APK侧自定义专属的唤起Action,避免写错Activity路径)

二、纯React Native(裸开发)实现步骤

  1. 可直接用react-native-send-intent包简化原生Intent交互操作:
    • 安装命令:npm i react-native-send-intent --save
    • 安卓11及以上系统要求应用主动声明要查询的包名,否则无法识别已安装应用,需要在当前RN应用的AndroidManifest.xml中添加如下配置:
    <queries>
      <package android:name="com.yourcompany.selfdeveloped.app" />
    </queries>
    
  2. 按钮点击事件代码示例:
    import SendIntentAndroid from 'react-native-send-intent';
    
    const openSelfDevelopedApk = async () => {
      // 先判断目标应用是否已安装
      const isInstalled = await SendIntentAndroid.isAppInstalled('com.yourcompany.selfdeveloped.app');
      if (isInstalled) {
        // 直接唤起目标应用
        SendIntentAndroid.openApp('com.yourcompany.selfdeveloped.app');
      } else {
        // 可自定义未安装的提示逻辑
        console.log('目标应用未安装');
      }
    }
    

三、Expo开发实现步骤

Expo环境无需预编译原生代码,使用官方提供的expo-intent-launcher包即可实现:

  1. 安装依赖:npx expo install expo-intent-launcher expo-modules-core
  2. 同样需要在app.json中配置安卓包查询权限,适配安卓11及以上系统:
    "android": {
      "queries": {
        "packages": ["com.yourcompany.selfdeveloped.app"]
      }
    }
    
  3. 按钮点击事件代码示例:
    import * as IntentLauncher from 'expo-intent-launcher';
    import { Alert } from 'react-native';
    
    const openSelfDevelopedApk = async () => {
      try {
        await IntentLauncher.startActivityAsync(
          IntentLauncher.ActivityAction.MAIN,
          {
            packageName: 'com.yourcompany.selfdeveloped.app',
            className: 'com.yourcompany.selfdeveloped.app.MainActivity'
          }
        );
      } catch (e) {
        Alert.alert('提示', '目标应用未安装在当前设备中');
      }
    }
    

注意事项

  • 如果需要在两个应用间传递参数,可以在Intent中额外添加extra字段传递数据,全程不需要任何网络请求
  • 如果希望自研APK不被其他任意应用唤起,可以在自研APK的AndroidManifest.xml中给目标Activity添加自定义权限,只有你的RN/Expo应用申请了对应权限才能唤起,可自行控制安全性

内容的提问来源于stack exchange,提问作者Indunil Girihagama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 03:15:11