gpt4 book ai didi

java - Android WebView 不加载自动重定向 url

转载 作者:行者123 更新时间:2023-11-29 04:34:46 24 4
gpt4 key购买 nike

我有一个需要打开特定链接的 WebView 。当我点击该链接时,它会将我重定向到另一个链接...我的问题是我能够打开第一个链接但没有调用第二个链接...请帮助我!

这是我的代码:

public class OnlinePayment extends AppCompatActivity {
WebView online_payment_activity_web_view;
String url;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.online_payment_activity);
Bundle extras = getIntent().getExtras();
url = extras.getString("redirect_url");
final ProgressDialog pd = ProgressDialog.show(OnlinePayment.this, "", "Redirecting...", true);
Log.e("Here redirect first", url);
online_payment_activity_web_view=(WebView) findViewById(R.id.online_payment_web_view);
online_payment_activity_web_view.getSettings().setJavaScriptEnabled(true);
online_payment_activity_web_view.getSettings().setSupportZoom(true);
online_payment_activity_web_view.getSettings().setBuiltInZoomControls(true);
online_payment_activity_web_view.getSettings().setDisplayZoomControls(false);
online_payment_activity_web_view.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
online_payment_activity_web_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
online_payment_activity_web_view.setWebChromeClient(new WebChromeClient());
online_payment_activity_web_view.getSettings().setLoadWithOverviewMode(true);
online_payment_activity_web_view.getSettings().setUseWideViewPort(true);
online_payment_activity_web_view.setWebViewClient(new WebViewClient() {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
/**
* Notify the host application that an SSL error occurred while loading a
* resource. The host application must call either handler.cancel() or
* handler.proceed(). Note that the decision may be retained for use in
* response to future SSL errors. The default behavior is to cancel the
* load.
*
* @param view The WebView that is initiating the callback.
* @param handler An SslErrorHandler object that will handle the user's
* response.
* @param error The SSL error object.
*/
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
//final AlertDialog.Builder builder = new AlertDialog.Builder(OnlinePayment.this);
String msg="";
if(error.getPrimaryError()==SslError.SSL_DATE_INVALID
|| error.getPrimaryError()== SslError.SSL_EXPIRED
|| error.getPrimaryError()== SslError.SSL_IDMISMATCH
|| error.getPrimaryError()== SslError.SSL_INVALID
|| error.getPrimaryError()== SslError.SSL_NOTYETVALID
|| error.getPrimaryError()==SslError.SSL_UNTRUSTED) {
if(error.getPrimaryError()==SslError.SSL_DATE_INVALID) {
msg="The date of the certificate is invalid";
} else if(error.getPrimaryError()==SslError.SSL_INVALID) {
msg="A generic error occurred";
} else if(error.getPrimaryError()== SslError.SSL_EXPIRED) {
msg="The certificate has expired";
} else if(error.getPrimaryError()== SslError.SSL_IDMISMATCH) {
msg="Hostname mismatch";
}
else if(error.getPrimaryError()== SslError.SSL_NOTYETVALID){
msg="The certificate is not yet valid";
} else if(error.getPrimaryError()==SslError.SSL_UNTRUSTED){
msg="The certificate authority is not trusted";
}
}
final AlertDialog.Builder builder = new AlertDialog.Builder(OnlinePayment.this);
builder.setMessage(msg);
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.e("---URL onPageStarted---", url);
pd.show();
String [] restructured_url = url.split("\\?");
Log.d("URL NEW----", restructured_url[0]);
if(restructured_url[0].equalsIgnoreCase(Utils.MAIN_URL+"/cgp_dashboard")){
Utils.dashBoardRefresh = true;
pd.hide(); StoreSharePreference.SSP().putBoolean StoreSharePreference.SSP().putBoolean("payment_processed", true);
Log.e("INSIDE SUCCESS", "------");
StoreSharePreference.SSP().putBoolean("isCGPCustomer", true);
StoreSharePreference.SSP().putString("cgp_customer", "yes");
Intent intent = new Intent(OnlinePayment.this, CherishMain.class);
intent.putExtra("fromPayment", true);
intent.putExtra("paymentSucess", true);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP |intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
// Move to dashboard
} else if(restructured_url[0].equalsIgnoreCase(Utils.MAIN_URL+"/customermaster/paymentfail")) {
StoreSharePreference.SSP().putBoolean("payment_processed", false);
Log.e("OUTSIDE SUCCESS", "------");
if (StoreSharePreference.SSP().getBoolean("isCGPCustomer", false) == true || StoreSharePreference.SSP().getString("cgp_customer").equals("yes")) {
Intent intent = new Intent(OnlinePayment.this, CherishMain.class);
intent.putExtra("fromPayment", true);
intent.putExtra("paymentSucess", false);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP |intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
// Move to dashboard
} else {
Toast.makeText(getBaseContext(), "Payment failed", Toast.LENGTH_LONG).show();
onBackPressed();
}
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view,url);
Log.e("---URL ORIGINAL---", url);
String javascript="javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'initial-scale=1.0,maximum-scale=10.0');";
view.loadUrl(javascript);
if(pd.isShowing()){
pd.hide();
}
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
online_payment_activity_web_view.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
}
online_payment_activity_web_view.loadUrl(url);
}

最佳答案

你应该使用

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}

请关注google official link了解更多信息。

关于java - Android WebView 不加载自动重定向 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42130115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com