Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 中 webview 怎麼用 localStorage

android 中 webview 怎麼用 localStorage

編輯:關於Android編程

我在 android裡面 使用html5的 localStorage
為什麼存不進去也讀不出來呀?
網上搜了好多都沒效果

mainWebView = (WebView)this.findViewById(R.id.mainWebView);
    WebSettings settings = mainWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true); 
    settings.setDatabaseEnabled(true);
     String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();  
    settings.setDatabasePath(dir);  
    settings.setDomStorageEnabled(true);
    settings.setGeolocationEnabled(true);

解決方案:

mWebView.getSettings().setDomStorageEnabled(true);  
mWebView.getSettings().setAppCacheMaxSize(1024*1024*8); 
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath(); 
mWebView.getSettings().setAppCachePath(appCachePath); 
mWebView.getSettings().setAllowFileAccess(true); 

mWebView.getSettings().setAppCacheEnabled(true); 

這個測試了是可以的

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved