Android如何通过scheme跳转界面

所属分类: 软件编程 / Android 阅读数: 33
收藏 0 赞 0 分享

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

需求

通过后台返回链接地址

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

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

实现

1.在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>

2.实现跳转

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();
    }
  }

3.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);
}

填坑

1.如下两个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"/*没有配置host 和path*/
        />
   </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>

2.如果不同的链接都要跳到一个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开发之Json文件的读写的示例代码

这篇文章主要介绍了android开发之Json文件的读写的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android7.0指纹服务FingerprintService实例介绍

这篇文章主要介绍了Android7.0指纹服务FingerprintService介绍,需要的朋友可以参考下
收藏 0 赞 0 分享

Android JNI处理图片实现黑白滤镜的方法

这篇文章主要介绍了Android JNI处理图片实现黑白滤镜的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android引入OpenCV的示例

本篇文章主要介绍了Android引入OpenCV的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android Zip解压缩工具类分享

这篇文章主要为大家详细介绍了Android Zip解压缩工具类,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Android RxJava创建操作符Interval

这篇文章主要为大家详细介绍了Android RxJava创建操作符Interval的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

5分钟快速实现Android爆炸破碎酷炫动画特效的示例

本篇文章主要介绍了5分钟快速实现Android爆炸破碎酷炫动效的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android 指纹功能实例代码

本文通过一个demo给大家介绍了android指纹功能,代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友参考下吧
收藏 0 赞 0 分享

Android实现倒计时CountDownTimer使用详解

这篇文章主要为大家详细介绍了Android实现倒计时CountDownTimer的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Android RxJava创建操作符Timer的方法

这篇文章主要为大家详细介绍了Android RxJava创建操作符Timer的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享
查看更多