情况如下:我创建了一个加载https://cstudios.sk/pemobil/的 webview 应用程序。该网站在原生 android 浏览器和 chrome 上都能正常工作。在大多数手机上也可以,但在 Galaxy S4 上,系统不会渲染某些部分。稍后,在使用下,它会部分纠正自己,但不会完全纠正。
https://www.dropbox.com/s/c9jtb9fc4fvohls/2013-08-02%2000.14.42.png << 渲染不良页面的屏幕。
MainActivity.java:
package sk.cstudios.pizzaextraonline;
import android.R.bool;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MainActivity extends Activity {
WebView pizzaExtraView;
ProgressDialog loadingMessage;
boolean loaded;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!isNetworkAvailable())
{
new AlertDialog.Builder(this)
.setTitle(getResources().getString(R.string.nonet_title))
.setMessage(getResources().getString(R.string.nonet_description))
.setPositiveButton(getResources().getString(R.string.nonet_closeapp), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with close app
finish();
}
})
.setNegativeButton(getResources().getString(R.string.nonet_gosettings), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// go to settings
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.wifi.WifiSettings");
startActivity(intent);
finish();
}
})
.show();
} else {
loaded = false;
pizzaExtraView = (WebView) findViewById(R.id.webview);
pizzaExtraView.setWebViewClient(new Cwebview());
WebSettings webSettings = pizzaExtraView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDatabasePath("data/data/com.xxx/databases");
webSettings.setDomStorageEnabled(true);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setSupportZoom(false);
webSettings.setAllowFileAccess(true);
webSettings.setSavePassword(true);
webSettings.setSupportMultipleWindows(false);
webSettings.setAppCacheEnabled(true);
webSettings.setAppCachePath("");
webSettings.setAppCacheMaxSize(5*1024*1024);
webSettings.setRenderPriority(RenderPriority.HIGH);
pizzaExtraView.loadUrl("https://cstudios.sk/pemobil/");
}
}
@SuppressLint("NewApi")
public class Cwebview extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//if (Uri.parse(url).getHost().equals("https://cstudios.sk/") || Uri.parse(url).getHost().equals("https://www.cstudios.sk/")) {
if(true) {
//pizzaExtraView.loadUrl(url);
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
return false;
}
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
/*Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);*/
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(!loaded) {
loadingMessage = ProgressDialog.show(MainActivity.this,getResources().getString(R.string.loading_title),getResources().getString(R.string.loading_decription),true);
}
}
@Override
public void onPageFinished(WebView view, String url)
{
if(!loaded) {
loadingMessage.dismiss();
loaded = true;
}
}
}
private long lastpressed;
private static final int PERIOD = 333;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
if((event.getEventTime() - lastpressed) < PERIOD)
{
Log.println(10, "testing", "doubletapped");
finish();
} else {
lastpressed = event.getEventTime();
Context context = getApplicationContext();
Toast toast = Toast.makeText(context, getResources().getString(R.string.back_hint), Toast.LENGTH_SHORT);
toast.show();
pizzaExtraView.goBack();
return true;
}
}
return false;
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
}
和清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sk.cstudios.pizzaextraonline"
android:versionCode="3"
android:versionName="1.0.020803" android:installLocation="preferExternal">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:hardwareAccelerated="true" >
<activity
android:name="sk.cstudios.pizzaextraonline.splash"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="sk.cstudios.pizzaextraonline.MainActivity"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
知道是什么导致了问题吗?您可以自由测试该站点,它尚未连接到订购系统。