从 浏览器 打开自己指 定的 app

本文以 app://my.csdn.net/news?id=210&path=1

为例子,然后你要知道 什么是  URI  和 URL,以及Intent 的传参 规范!

URI uri = new URI("http://my.csdn.net/news?id=210&path=1");


System.out.println(uri.getScheme()); // app


System.out.println(uri.getHost());  // my.csdn.net 这个就是Android 里面的 包名(com.xxxx.xxxx)


System.out.println(uri.getPath());  // /news 这个就是 你的 类名(xxxxActivity)


System.out.println(uri.getQuery()); // id=210&path=1  要是有条件帅选的话 这个可以传参


然后在 App 里面只需要这样组装Inten,指定包名(Host),然后指定Action名(path),然后增加传递的数据和Fragment(Query)。

这样就很好的把一个跳转到某个应用某个页面的的行为用URI指定出来。方便应用和应用之间相互跳转。

Intent intent = new Intent();
intent.setPackage(uri.getHost());
intent.setAction(uri.getPath());


最后在Manifest.xml对应的 activity中注册 

<activity android:name="YourActivity"

          android:label="@string/app_name">
    <!--要想在别的App上能成功调起App,必须添加intent过滤器-->
    <intent-filter>
        <!--协议部分-->
       <data android:host="my.csdn.net" android:scheme="app" />
        <!--下面这几行也必须得设置-->
        <category android:name="android.intent.category.DEFAULT"/>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
    </intent-filter>
</activity>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值