Android如何通过scheme跳转界面
2017-07-25 16:12
519 查看
Android通过scheme跳转界面,应该如何实现?
需求
通过后台返回链接地址
eg: app://com.bobo.package/path?param1=abc¶m2=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¶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 跳转界面时 ,系统会提示选择打开方式 因为没有精确匹配要跳哪个界面
<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¶m2=cde
application://host/route?param1=abc¶m2=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跳转界面
- 23、Android开发基础之通过隐式意图来实现界面的跳转
- android:scheme 通过uri跳转到APP应用指定Activity
- android中如何实现进入一个界面不做任何动作过10秒钟自动跳转到其他activity?
- Android如何在app中通过一个按钮直接跳转到的系统的权限设置页面
- 在Android中如何Intent意图跳转系统其他的界面
- android中如何实现进入一个界面不做任何动作过10秒钟自动跳转到其他activity?
- Android如何通过TextView实现超链接的跳转
- Android 判断应用程序获取通知栏权限是否开启,以及如何跳转到应用程序设置界面
- Android中关于如何从一个Activity跳转到拨号界面,或者直接到通话中
- android 如何能使界面跳转到系统网络设置界面
- android中如何实现进入一个界面不做任何动作过10秒钟(有操作从新计时)自动跳转到待机activity,点击待机界面回到原来的界面
- 【风马一族_Android】通过菜单的点击,跳转到不同界面
- android通过Intent跳转到添加联系人界面的小结
- 在Android 4.0中Contacts 通话记录界面跳转通话详情的是如何实现的(精析)
- Android如何在app中通过一个按钮直接跳转到的系统的权限设置页面
- android中通过网络请求数据显示在Listview中,面对许多的item,如何给每个item设置点击事件以跳转到不同的activity
- Android:scheme 通过uri跳转到APP前后台代码实现
- Android使用ListView构造复杂界面,响应点击事件,通过Intent跳转activity
- android scheme 跳转应用 如何获取intent传的参数