我们的Android应用程序嵌入了一些在线应用程序以实现某些功能。该应用程序使用两个网站来执行此功能。 Web视图的简化版本如下:
活动
public class MainActivity extends AppCompatActivity implements IWebViewCallback {
private WebView browser;
private ImageButton backButton;
private ImageButton homeButton;
private ImageButton forwardButton;
private String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sharedPref = this.getSharedPreferences("Qp", Context.MODE_PRIVATE);
url = sharedPref.getString("url", "");
if (url.isEmpty()) {
url = "https://10.10.9.200:8443/pay/";
SharedPreferences.Editor editor = sharedPref.edit();
//editor.putString("url", "https://payment.kbzbank.com");
editor.putString("url", url);
editor.commit();
}
browser = (WebView) findViewById(R.id.browser);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
setMixedContentMode();
browser.setWebViewClient(new QWebClient(this));
if (isNetworkAvailable())
browser.loadUrl(url);
else
browser.loadUrl("file:///android_asset/error.html");
backButton = (ImageButton) findViewById(R.id.back);
homeButton = (ImageButton) findViewById(R.id.home);
forwardButton = (ImageButton) findViewById(R.id.forward);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (browser.canGoBack()) {
if (isNetworkAvailable())
browser.goBack();
else
browser.loadUrl("file:///android_asset/error.html");
}
}
});
homeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
browser.loadUrl(url);
}
});
forwardButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (browser.canGoForward()) {
if (isNetworkAvailable())
browser.goForward();
else
browser.loadUrl("file:///android_asset/error.html");
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 200) {
if (resultCode == 200) {
if (isNetworkAvailable()) {
SharedPreferences sharedPref = this.getSharedPreferences("Qp", Context.MODE_PRIVATE);
url = sharedPref.getString("url", "");
browser.loadUrl(url);
} else {
browser.loadUrl("file:///android_asset/error.html");
}
}
}
}
@Override
public void connectionError() {
browser.loadUrl("file:///android_asset/error.html");
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
private void setMixedContentMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
browser.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
}
}
Web客户端
public class QpWebClient extends WebViewClient {
private IWebViewCallback callback;
public QpWebClient(IWebViewCallback callback) {
this.callback = callback;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
Log.d("webview", "proceeding");
handler.proceed();
error.getCertificate();
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
Log.d("webview", "onReceivedError: " + error.toString());
callback.connectionError();
super.onReceivedError(view, request, error);
}
}
Web视图被告知如果出现SSL绕过SSL错误。
Web应用程序将用户重定向到另一个安全站点进行处理。网络视图停在那里。
问题是网页中的分号。以下是嵌入式浏览器生成的日志:
27493-27493/com.some.package I/chromium: [INFO:CONSOLE(1)] "The value "yes;" for key "user-scalable" is invalid, and has been ignored.", source: https://some.site (1)
12-05 16:47:14.013 27493-27493/com.some.package I/chromium: [INFO:CONSOLE(1)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://some.site(1)
问题的原因很清楚。 Android SDK's GitHub site已报告此问题。并且网站应commas not semicolons用于视口。
Android 5.0之前的嵌入式浏览器工作(可能是因为它们是基于webkit的),但Android 5.0中的浏览器向上失败。该页面也适用于从Play商店下载的Chrome浏览器。
我们遇到的问题是失败的页面是第三方门户的登录页面,我们不能要求他们更正他们的页面。
我想知道是否有解决此问题的解决方法。