Android 页面Scheme配置

一、URL Scheme 的作用

Scheme 用于从浏览器或其他应用中启动本应用。也就是说要从其他应用中跳转本应用的界面或者网页跳转本应用打开特定的界面。

二、 在 Android 应用中配置 Scheme

1、 只有一个 Scheme 的情况下

在 AndroidManifest.xml 中定义 intent-filter,代码实例:

<activity
 
  android:name=".MainActivity"
 
  android:label="@string/app_name"
 
  android:launchMode="singleTask"
 
  android:theme="@style/AppTheme.NoActionBar">
 
  <intent-filter>
 
    <action android:name="android.intent.action.MAIN" />
 
    <category android:name="android.intent.category.LAUNCHER" />
 
  </intent-filter>
 
  <!-- 在主 Activity 中配置 scheme-->
 
  <intent-filter>
 
    <action android:name="android.intent.action.VIEW" />
 
    <category android:name="android.intent.category.BROWSABLE" />
 
    <category android:name="android.intent.category.DEFAULT" />
 
    <data
 
      android:host="test"// 这个直接加到下面也行
 
      android:scheme="http//" />//自取名字,可随意命名,提前订好协议
  </intent-filter>
 
</activity>

这个时候通过 URL http//test就可以把应用调起来了。

2、两个或者两个以上的 Scheme 添加

如果我们的应用需要配置多个 Scheme,可以配置多个 intent-filter,代码示例:

<activity
 
  android:name=".MainActivity"
 
  android:label="@string/app_name"
 
  android:launchMode="singleTask"
 
  android:theme="@style/AppTheme.NoActionBar">
 
  <intent-filter>
 
    <action android:name="android.intent.action.MAIN" />
 
    <category android:name="android.intent.category.LAUNCHER" />
 
  </intent-filter>
 
  <!-- 在主 Activity 中配置 scheme-->
 
  <intent-filter>
 
    <action android:name="android.intent.action.VIEW" />
 
    <category android:name="android.intent.category.BROWSABLE" />
 
    <category android:name="android.intent.category.DEFAULT" />
 
    <data
 
      android:host="debugmode"
 
      android:scheme="http//" />
 
  </intent-filter>
 
  <intent-filter>
 
    <action android:name="android.intent.action.VIEW" />
 
    <category android:name="android.intent.category.BROWSABLE" />
 
    <category android:name="android.intent.category.DEFAULT" />
 
    <data
 
      android:host="test"
 
      android:scheme="http//" />
 
  </intent-filter>
 
  <intent-filter>
 
    <action android:name="android.intent.action.VIEW" />
 
    <category android:name="android.intent.category.BROWSABLE" />
 
    <category android:name="android.intent.category.DEFAULT" />
 
    <data
 
      android:host="test2"
 
      android:scheme="https" />
 
  </intent-filter>
 
</activity>

也有人说在同一个 intent-filter 标签里面配置多个 data 标签也是可以实现功能的。

一般情况下是没有什么问题的,虽然同一过滤器可以包含多个 <data> 元素,但如果您想要声明唯一网址(例如特定的 scheme 和 host 组合),请务必创建单独的过滤器,因为同一 intent 中的多个 <data> 元素实际上会合并在一起以涵盖合并后属性的所有变体。请看看以下代码示例:
 

 
<intent-filter>
 
  ...
 
  <data android:scheme="http" android:host="test" />
 
  <data android:scheme="https" android:host="test2" />
 
</intent-filter>

intent 过滤器似乎仅支持 http://test 和 https:/test2

其实,还有另外两项:http://test2 和 https://test

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp scheme是用于配置uniapp应用程序的URL Scheme的一种设置。URL Scheme是一种用于在应用程序之间进行通信的机制,允许应用程序通过URL来启动其他应用程序或执行特定的操作。在uniapp中,可以通过配置URL Scheme来实现从H5页面跳转到原生应用程序的功能。 在uniapp中,配置URL Scheme的步骤如下: 1. 首先,在manifest.json文件中找到"app-plus"->"distribute"->"ios"节点,配置URL Scheme的值,示例如下: "app-plus": { "distribute": { "ios": { "urltypes": "test,myuniapp" //... }, //... }, //... } 这样配置后,iOS应用程序就可以通过test和myuniapp这两个URL Scheme来跳转到uniapp应用程序。 2. 对于Android平台,同样在manifest.json文件中找到"app-plus"->"distribute"->"android"节点,配置URL Scheme的值,示例如下: "app-plus": { "distribute": { "android": { "schemes": "test,myuniapp" //... }, //... }, //... } 这样配置后,Android应用程序就可以通过test和myuniapp这两个URL Scheme来访问uniapp应用程序。 需要注意的是,具体的URL Scheme的值可以根据实际需求进行配置,可以根据需要添加更多的URL Scheme。同时,还可以参考uniapp官方文档中的相关教程来进行更详细的配置和了解。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *2* [跨平台应用开发进阶(十六) :uni-app实现URLScheme方式唤醒APP](https://blog.csdn.net/sunhuaqiang1/article/details/124992935)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [uniapp利用scheme启动App](https://blog.csdn.net/Mitin_/article/details/127520579)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值