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

需求

通过后台返回链接地址

eg: app://com.bobo.package/path?param1=abc¶m2=cde

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

实现

1.在manifest中配置Activity

                           

2.实现跳转

private void startActivity(Context context) {    try {      Uri uri = Uri.parse("app://com.bobo.package/path?param1=abc¶m2=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 跳转界面时 ,系统会提示选择打开方式 因为没有精确匹配要跳哪个界面

                                                      

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

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

Activity配置

                               

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多相关文章

  1. 一起学android之SimpleAdapter使用(13)
  2. AndroidUI设计之ViewPaper详解
  3. Android学习笔记:Activity-Spinner
  4. 几个Android常见wraning警告处理方法
  5. Android(安卓)WebView使用基础
  6. Android(安卓)的网络编程(4)-HttpClient接口
  7. Android中比较常见的Java super关键字
  8. android界面设计(一)侧边栏的两种实现方式
  9. Android(安卓)使用Instrumentation进行界面的单元测试

随机推荐

  1. 15个基于WEB的HTML编辑器
  2. 另一个div内的任意宽度的中心div
  3. css3+html5——拼接图片中icon的使用、照
  4. 认识DHTML中的“行为”组件
  5. 如何从input type = file中删除一个对象?
  6. 如何在jquery中增加itemtype的值?
  7. xml格式原样输出到html或是jsp页面
  8. 用HTML+CSS编写一个计科院网站首页的静态
  9. 布局的标记建议和一些更一般的问题
  10. IDEA SpringBoot入门与速查—HTML页与Thy