網上很多都是提供自己的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 工程資源引用;包名,簽名證書是否和註冊一致")
}
})
}