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

本文介绍了一种在App内部打开特定网页的方法,包括配置文件的修改、参数传递及界面展示等步骤,确保从外部调起App时能正确加载指定页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.jianshu.com/p/1439c8bbc34b
http://blog.youkuaiyun.com/qiushi_1990/article/details/51355073
http://blog.youkuaiyun.com/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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值