Android如何通过scheme跳转界面
16lz
2021-01-25
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配置
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
更多相关文章
- 一起学android之SimpleAdapter使用(13)
- AndroidUI设计之ViewPaper详解
- Android学习笔记:Activity-Spinner
- 几个Android常见wraning警告处理方法
- Android(安卓)WebView使用基础
- Android(安卓)的网络编程(4)-HttpClient接口
- Android中比较常见的Java super关键字
- android界面设计(一)侧边栏的两种实现方式
- Android(安卓)使用Instrumentation进行界面的单元测试