微信内H5唤醒本地安装应用终于有解决方案了

来源:互联网 发布:php 判断不为小数 编辑:程序博客网 时间:2024/05/18 06:21

我之前做了好多工作,就是解决不了在微信内打开的H5唤醒我的本地应用并且跳转到指定的页面。之前我是这么做的

1 主要是在AndroidManifest.xml里面的配置,配置你的应用中从头到尾不会被回收掉的那个activity上

* 注意:android:scheme 是你app在微信开发者申请的appid,微信使用的是qq浏览器的内核,内部把这一层拦截了,这就是你用手机上的浏览器可以打开,在微信里就打不开了,这就是原因,你需要用appid作为scheme让微信去识别*

<!-- 主界面 -->        <activity            android:name=".MainActivity"            android:screenOrientation="portrait"            android:exported="true"            android:launchMode="singleTop"            android:taskAffinity="com.xxxxxxx.xxxx.xxxx"            android:windowSoftInputMode="adjustPan|stateHidden">            <!--要想在别的App上能成功调起App,必须添加intent过滤器-->           <!--android:host 参数自己可以随便写-->            <!--wx52662xxxxxxxxxx://xxxx.uri.activity?finds_id=4  Open links like scheme://host/?…-->            <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:host="doer.uri.activity"                    android:scheme="wx52662xxxxxxxxxx"/>            </intent-filter>        </activity>
2 在mainactivity里这样接收:
 /**     * 接收H5唤醒app跳转指定页面的逻辑     */    private void initGetData() {        intent = getIntent();        if (null != intent) {            Uri uri = intent.getData();            if (uri == null) {                return;            }            //testapp://test.uri.activity?action=1            String acionData = uri.getQueryParameter("action");            String find_id = uri.getQueryParameter("finds_id");            if (null != acionData && acionData.equals("1")) {                String shops_id = uri.getQueryParameter("shops_id");                String goodsType_id = uri.getQueryParameter("goodsType_id");                String goods_id = uri.getQueryParameter("goods_id");                if (!TextUtils.isEmpty(shops_id)) {                    Intent go_shop_good = new Intent(MainActivity.this, WMShopActivity.class);                    go_shop_good.putExtra(getString(R.string.shops_id_key), Integer.valueOf(shops_id));                    startActivity(go_shop_good);                }                if (!TextUtils.isEmpty(goodsType_id)) {                    Intent go_shop_good = new Intent(MainActivity.this, WMShopActivity.class);                    go_shop_good.putExtra(getString(R.string.current_select_goodsType_id), Integer.valueOf(goodsType_id));                    startActivity(go_shop_good);                }                if (!TextUtils.isEmpty(goods_id)) {                    Intent go_shop_good = new Intent(MainActivity.this, WMShopActivity.class);                    go_shop_good.putExtra(getString(R.string.current_select_goods_id), Integer.valueOf(goods_id));                    startActivity(go_shop_good);                }            }            if (!TextUtils.isEmpty(find_id)) {                Intent go_find = new Intent(MainActivity.this, DiscoverDetailActivity.class);                go_find.putExtra(getString(R.string.find_id_key), Integer.valueOf(find_id));                startActivity(go_find);            }        }    }

在我印象中好像成功过几次,然后再也不行了,坑爹。

就在今天我又找到了一种解决方案:

那就是这个第三方帮我们解决了这个问题,最主要的是这个三方还免费。我不是为它打广告,我是有找到了一种解决方案比较兴奋才分享出来的。

网址:https://www.linkedme.cc/doc/content/LinkPage-Integration.html

自己看文档集成吧,so easy!



最后欢迎加入Kotlin QQ群,一起讨论学习:

Paste_Image.png

欢迎关注 微信公号

android频道

原创粉丝点击