在Android Webview上使用appcache时遇到问题

时间:2015-12-07 12:20:39

标签: java android jquery html5 webview

我正在使用Webview访问jQuery Mobile页面的移动应用程序,问题是Appcache没有保存我的页面,但它确实存储在浏览器上,我一直在搜索解决方案,但似乎没有一个在我的情况下工作。

非常感谢任何帮助!

这是我的Webview代码:

package com.enlac.tasking;

import java.io.File;

import com.enlac.tasking.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewActivity extends Activity {

    private WebView webView;

    @SuppressWarnings("deprecation")
    @SuppressLint("SetJavaScriptEnabled") public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDatabaseEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);

        String sDataPath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        webView.getSettings().setDatabasePath(sDataPath);
        webView.getSettings().setSavePassword(true);
        webView.getSettings().setAllowContentAccess(true);
        webView.getSettings().setAllowFileAccess(true); 
        File dir = getCacheDir();
        if (!dir.exists()) {
          dir.mkdirs();
        }
        webView.getSettings().setAppCachePath(dir.getPath());
        webView.getSettings().setAppCacheEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

        webView.setWebViewClient(new Callback());
        webView.setWebChromeClient(new webChromeClient());
        webView.loadUrl("I removed the link because I don't have the rights to show some stuff on it");



    }
    private class Callback extends WebViewClient{  

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

 }
 private class webChromeClient extends WebChromeClient
 {
     @SuppressWarnings("deprecation")
    @Override
        public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { 
         quotaUpdater.updateQuota(50 * 1024 * 1024); 
     }       
 }

}

Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.enlac.tasking"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.enlac.tasking.WebViewActivity"
            android:theme="@android:style/Theme.NoTitleBar" />

        <activity
            android:label="@string/app_name"
            android:name="com.enlac.tasking.MainActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

0 个答案:

没有答案