iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android通过scheme跳转界面的方法
  • 114
分享到

Android通过scheme跳转界面的方法

androidscheme 2023-05-30 23:05:56 114人浏览 薄情痞子
摘要

这篇文章主要介绍Android通过scheme跳转界面的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!Android通过scheme跳转界面,应该如何实现?需求通过后台返回链接地址eg: app://com.bo

这篇文章主要介绍Android通过scheme跳转界面的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

Android通过scheme跳转界面,应该如何实现?

需求

通过后台返回链接地址

eg: app://com.bobo.package/path?param1=abc&param2=cde

跳转到指定的Activity 并带入参数

实现

在manifest中配置Activity

<activity android:name=".ActivityName">   <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:scheme="app"         android:host="com.bobo.package"         android:path="/path"/>   </intent-filter></activity>

实现跳转

private void startActivity(Context context) {    try {      Uri uri = Uri.parse("app://com.bobo.package/path?param1=abc&param2=cde");      Intent intent = new Intent();      intent.setAction(Intent.ACTION_VIEW);      intent.setData(uri);      PackageManager packageManager=getPackageManager();      ComponentName componentName=intent.resolveActivity(packageManager);      if (componentName!=null){        context.startActivity(intent);      }    } catch (Exception e) {      e.printStackTrace();    }  }

Activity中处理数据获取参数

private void dealScheme() {    Intent intent = getIntent();    String action = intent.getAction();    Uri uri=null;    if (Intent.ACTION_VIEW.equals(action)) {      Uri uri= intent.getData();    }    if(uri==null)      return;    String param1=url.getQueryParameter("param1");    String param2=url.getQueryParameter("param2");    // doSomething(param1,param2);}

填坑

如下两个Activity 当通过scheme 跳转界面时 ,系统会提示选择打开方式 因为没有精确匹配要跳哪个界面

<activity android:name=".ActivityAAAAAA">   <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:scheme="app"        />   </intent-filter></activity><activity android:name=".ActivityBBBBBB">   <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:scheme="app"         android:host="com.bobo.package"        />   </intent-filter></activity>

如果不同的链接都要跳到一个Activity

eg: app://com.bobo.package/path?param1=abc&param2=cde
application://host/route?param1=abc&param2=cde

Activity配置

<activity android:name=".ActivityName">   <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:scheme="app"        android:host="com.bobo.package"        android:path="/path"/>     <data android:scheme="application"       android:host="host"       android:path="/route"/>   </intent-filter></activity>

以上是“Android通过scheme跳转界面的方法”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网精选频道!

--结束END--

本文标题: Android通过scheme跳转界面的方法

本文链接: https://www.lsjlt.com/news/221993.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作