android点击链接打开应用对应界面

来源:互联网 发布:filter 过滤css和js 编辑:程序博客网 时间:2024/06/08 10:25

http://www.jianshu.com/p/1439c8bbc34b
http://blog.csdn.net/qiushi_1990/article/details/51355073
http://blog.csdn.net/alone_slfly/article/details/41744323
参考以上完成,本想直接用上边给出的demo但是要的c币太多了,就自己写了一个,大概功能实现了。
用到的share.html放到了资源文件assets下边(share1.html有乱码了,将其改为txt然后另存为utf-8格式就好了)这两个.html是一样的,到时候将两个html文件放入手机中用浏览器打开即可。
1.首先在配置文件中在对应界面的activity中加入(我是在应用起始界面SplashActivity中添加的):

<activity android:name=".SplashActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />            <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>            <!--要想在别的App上能成功调起App,必须添加intent过滤器-->            <intent-filter>                <!--协议部分,zhyan://webopen:8888/app?-->                <data android:scheme="zhyan" android:host="webopen"                    android:path="/app" android:port="8888"/>                <!--下面这几行也必须得设置-->                <category android:name="android.intent.category.DEFAULT"/>                <action android:name="android.intent.action.VIEW"/>                <category android:name="android.intent.category.BROWSABLE"/>            </intent-filter>        </activity>

2.在起始页添加获取参数,并将参数传递到要展示的界面。

 @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_splash);        if(Intent.ACTION_VIEW.equals(getIntent().getAction())){             String showUrl = uri.getQueryParameter("param_show_url");                String title = uri.getQueryParameter("param_title");                Intent resultIntent = new Intent(SplashActivity.this,ShowActivity.class);                resultIntent.putExtra("url",showUrl);                resultIntent.putExtra("title",title);        }

3.在应用杀死状态下,打开对应界面后,返回时为了不回到浏览器界面,可以借助TaskStackBuilder来实现(具体用法请查阅相关文档)

         <activity            android:name=".ShowActivity"            android:parentActivityName=".MainActivity" />

4.可能界面会开启好几个,自己去设置下对应activity的launchMode即可
至此大概功能就实现了。
源码链接:
https://github.com/ZHuiYan/WebOpenApp/tree/master

阅读全文
0 0