网上很多都是提供自己的app让别人来打开,这里学习一下打开其他app方式

淘宝的跳转:
淘宝的跳转使用的是淘宝的sdk阿里百川
相关使用方法根据开发文档即可。

  • 京东的跳转:
    京东的跳转有2种方法:
    1 不接入sdk,使用intent跳转的方式调起:(此种方式需要使用商品的id,对于转链后的商品链接无法适用,可以使用第二种方法)

 

 /**
     * 进入jd页面
     *京东包名:com.jingdong.app.mall
     */
    public static void goJd(Context context, String id, String thridPlatSearchKey) {
        if (checkApkExist(Application.instance, "com.jingdong.app.mall")) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            Uri uri = Uri.parse("openapp.jdmobile://virtual?params=%7B%22sourceValue%22:%220_productDetail_97%22,%22des%22:%22productDetail%22,%22skuId%22:%22"+id+"%22,%22category%22:%22jump%22,%22sourceType%22:%22PCUBE_CHANNEL%22%7D ");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(uri);
            context.startActivity(intent);
        } else {
            Toast.makeText(Application.instance, "本机未安装京东应用", Toast.LENGTH_SHORT).show();
        }
    }

2 接入京东sdk京东云宙斯
接入之后可以使用以下代码跳转:

 

   @JavascriptInterface
    override fun gotoJD(url: String?) {
        CommonModule.getApplicationContext().runOnUiThread {
            if (mKeplerAttachParameter == null)
                mKeplerAttachParameter = KeplerAttachParameter()
            val mOpenAppAction = OpenAppAction { status, url ->
                if (status == OpenAppAction.OpenAppAction_start) {//开始状态未必一定执行,
                    showLoadingDialog()
                } else {
                    dismissLoadingDialog()
                }
                if (status == OpenAppAction.OpenAppAction_result_NoJDAPP) {
                    //未安装京东
                    (mFragment as? WebFragment)?.loadUrl("$url")
                } else if (status == OpenAppAction.OpenAppAction_result_BlackUrl) {
                    //不在白名单
                    KLog.e("KeplerApiManager-京东-不在白名单")
                } else if (status == OpenAppAction.OpenAppAction_result_ErrorScheme) {
                    //协议错误
                    KLog.e("KeplerApiManager-京东-协议错误")
                } else if (status == OpenAppAction.OpenAppAction_result_APP) {
                    //呼京东成功
                    KLog.e("KeplerApiManager-京东-呼京东成功")
                } else if (status == OpenAppAction.OpenAppAction_result_NetError) {
                    //网络异常
                    KLog.e("KeplerApiManager-京东-网络异常")
                    Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show()
                }
            }
            // 通过url呼京东主站
            // url 通过url呼京东主站的地址
            // mKeplerAttachParameter 存储第三方传入参数
            // mOpenAppAction  呼京东主站回调
            KeplerApiManager.getWebViewService().openAppWebViewPage(mFragment?.context,
                    url,
                    mKeplerAttachParameter,
                    mOpenAppAction)
        }
    }

需要在application里面初始化:

 

    /**
     * 初始化京东联盟sdk
     */
    private fun initJDLM() {
        KeplerApiManager.asyncInitSdk(this, "01b31d82ece44bfb8fefa58610d3a52e", "d1f189ec2b21497c86587a5ef2625185",
                object : AsyncInitListener {
                    override fun onSuccess() {
                        KLog.e("Kepler", "Kepler asyncInitSdk onSuccess ")
                    }

                    override fun onFailure() {
                        KLog.e("Kepler",
                                "Kepler asyncInitSdk 授权失败,请检查lib 工程资源引用;包名,签名证书是否和注册一致")

                    }
                })
    }


 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐