本文以 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>