use*_*111 3 android webview android-intent android-activity
我想在网址加载完成后将webview重定向到另一个活动.这是我的webview代码: - 这个类由webview扩展
** 1) This the method where I am doing code for redirecting webview to activity**
Run Code Online (Sandbox Code Playgroud)
>这是onPagefinished方法,其中url正在加载.
public void onPageFinished(WebView view, String url) {
if (url.endsWith("paymentconfirmation/"))
((DibsPaymentScreen) getContext())
.setCancelDisallowed(false);
if (callbackUrl.equals(url)
&& statusCancelled.equals(paymentData.params
.get(statusKey))) {
paymentResultListener.cancelUrlLoaded();
} else if (callbackUrl.equals(url)
&& statusAccepted.equals(paymentData.params
.get(statusKey))) {
paymentResultListener.paymentAccepted(paymentData.params);
} else if (!windowIsLoaded) {
paymentWindowLoaded();
}
super.onPageFinished(view, url);
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals("http://nmotion.dk/paymentconfirmation/")) {
Intent intent = new Intent(getContext(),
RestaurantsListScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(intent);
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
您必须在WebView WebViewCLient中实现on finish loader
webview.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
// create your intent here
super.onPageFinished(view, url);
}
});
Run Code Online (Sandbox Code Playgroud)
编辑白色提供的代码
public void onPageFinished(WebView view, String url) {
if (url.equals("http://nmotion.dk/paymentconfirmation/")) {
Intent intent = new Intent(getContext(), RestaurantsListScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(intent);
return true;
} else {
if (url.endsWith("paymentconfirmation/")){
((DibsPaymentScreen) getContext()).setCancelDisallowed(false);
}
if (callbackUrl.equals(url) && statusCancelled.equals(paymentData.params.get(statusKey))) {
paymentResultListener.cancelUrlLoaded();
} else if (callbackUrl.equals(url)
&& statusAccepted.equals(paymentData.params.get(statusKey))) {
paymentResultListener.paymentAccepted(paymentData.params);
} else if (!windowIsLoaded) {
paymentWindowLoaded();
}
super.onPageFinished(view, url);
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
1204 次 |
| 最近记录: |