android 和 js互動 客戶端呼叫的方法
阿新 • • 發佈:2019-01-30
mWebView.setWebViewClient(new WebViewClient() {
// 點選H5的按鈕,跳轉到另一個介面,單機H5裡的提交按鈕判斷是否登入,onPageFinished()每次載入都會呼叫
@Overrid
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("login")) {
//未登入
if (!AccHelper.isLogin(AppContext.MainContext)) {
LikeIosDialog loginDialog = new LikeIosDialog(cn.cntv.ui.activity.HudongWebActivity.this);
loginDialog.setmUserDefinedMsg("您還沒有登入,是否登入?");
loginDialog.setOnCertainButtonClickListener(new LikeIosDialog.OnCertainButtonClickListener() {
@Override
public void onCertainButtonClick() {
startActivityForResult(new Intent(cn.cntv.ui.activity.HudongWebActivity.this, LoginActivity.class), 101);
// MobileAppTracker.trackEvent("登入", "", "邊看邊聊", 0, HudongWebActivity.this);
overridePendingTransition(R.anim.task_slide_in_right,
R.anim.task_slide_out_left);
}
@Override
public void onCancleButtonClick() {
}
});
loginDialog.setCancelable(false);
loginDialog.show();
}
return true;
}
//5.28日因songbo要求6.1.0版本註釋掉,下個版本再上線
// else if (url.startsWith("share")) {
// Log.e("yuedongwebactivity",url);
// try {
// //url: "share://www.cntv.com?mTitle=XXX&mImgUrl=XXX&mPath=XXX"
// Uri uri = Uri.parse(url.replace("share://", "http://"));
// // 匹配驗證碼
// mTitle = uri.getQueryParameter("mTitle"); //分享的標題
// mImgUrl = uri.getQueryParameter("mImgUrl");//小圖片的地址,大小在32k
// mPath = uri.getQueryParameter("mPath");//跳轉html5地址
//
// Log.e("yuedongwebactivity","mTitle="+mTitle+";;mImgUrl="+mImgUrl+";;mPath="+mPath);
//
// if (shareToPopupWindow != null)
// shareToPopupWindow.dismiss();
// shareToPopupWindow = ShareToPopupWindow.show("", false, HudongWebActivity.this, mTitle, mImgUrl, mPath, mTitle, false, findViewById(R.id.hudong_web_main));
// }
// catch (Exception ex)
// {
// ex.printStackTrace();
// }
// return true;
// }
else {
try {
if (!url.endsWith(".apk") && (url.startsWith("http:") || url.startsWith("https:"))) {
view.loadUrl(url);
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (mWebView != null) {
mWebView.loadUrl("javascript:shareForAndroid()");
if (AccHelper.isLogin(AppContext.MainContext)) {
mWebView.loadUrl("javascript:cboxGetUserStatus('" + AccHelper.getUserId(cn.cntv.ui.activity.HudongWebActivity.this) + "','" + AccHelper.getVerifycode(cn.cntv.ui.activity.HudongWebActivity.this) + "')");
}
}
}
});
// 點選H5的按鈕,跳轉到另一個介面,單機H5裡的提交按鈕判斷是否登入,onPageFinished()每次載入都會呼叫
@Overrid
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("login")) {
//未登入
if (!AccHelper.isLogin(AppContext.MainContext)) {
LikeIosDialog loginDialog = new LikeIosDialog(cn.cntv.ui.activity.HudongWebActivity.this);
loginDialog.setmUserDefinedMsg("您還沒有登入,是否登入?");
loginDialog.setOnCertainButtonClickListener(new LikeIosDialog.OnCertainButtonClickListener() {
@Override
public void onCertainButtonClick() {
startActivityForResult(new Intent(cn.cntv.ui.activity.HudongWebActivity.this, LoginActivity.class), 101);
// MobileAppTracker.trackEvent("登入", "", "邊看邊聊", 0, HudongWebActivity.this);
overridePendingTransition(R.anim.task_slide_in_right,
R.anim.task_slide_out_left);
}
@Override
public void onCancleButtonClick() {
}
});
loginDialog.setCancelable(false);
loginDialog.show();
}
return true;
}
//5.28日因songbo要求6.1.0版本註釋掉,下個版本再上線
// else if (url.startsWith("share")) {
// Log.e("yuedongwebactivity",url);
// try {
// //url: "share://www.cntv.com?mTitle=XXX&mImgUrl=XXX&mPath=XXX"
// Uri uri = Uri.parse(url.replace("share://", "http://"));
// // 匹配驗證碼
// mTitle = uri.getQueryParameter("mTitle"); //分享的標題
// mImgUrl = uri.getQueryParameter("mImgUrl");//小圖片的地址,大小在32k
// mPath = uri.getQueryParameter("mPath");//跳轉html5地址
//
// Log.e("yuedongwebactivity","mTitle="+mTitle+";;mImgUrl="+mImgUrl+";;mPath="+mPath);
//
// if (shareToPopupWindow != null)
// shareToPopupWindow.dismiss();
// shareToPopupWindow = ShareToPopupWindow.show("", false, HudongWebActivity.this, mTitle, mImgUrl, mPath, mTitle, false, findViewById(R.id.hudong_web_main));
// }
// catch (Exception ex)
// {
// ex.printStackTrace();
// }
// return true;
// }
else {
try {
if (!url.endsWith(".apk") && (url.startsWith("http:") || url.startsWith("https:"))) {
view.loadUrl(url);
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (mWebView != null) {
mWebView.loadUrl("javascript:shareForAndroid()");
if (AccHelper.isLogin(AppContext.MainContext)) {
mWebView.loadUrl("javascript:cboxGetUserStatus('" + AccHelper.getUserId(cn.cntv.ui.activity.HudongWebActivity.this) + "','" + AccHelper.getVerifycode(cn.cntv.ui.activity.HudongWebActivity.this) + "')");
}
}
}
});