</pre><pre name="code" class="java">
</pre><pre name="code" class="java">
//不得不说,官网的api是个大坑。
</pre><pre name="code" class="java">package com.app.phone;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.cordova.Config;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
public class index extends Activity implements CordovaInterface {
CordovaWebView cwv;
private final ExecutorService threadPool =Executors.newCachedThreadPool();
private CordovaPlugin activityResultCallback =null;
protected boolean activityResultKeepRunning;
// Keep app running when pause is received. (default = true)
// If true, then the JavaScript and native code continue to run in the
// background
// when another application (activity) is started.
protected boolean keepRunning = true;
/* Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.index);
cwv = (CordovaWebView) findViewById(R.id.tutorialView);
cwv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); //设置 缓存模式
//开启 database storage API 功能
cwv.getSettings().setDatabaseEnabled(true);
String cacheDirPath = getFilesDir().getAbsolutePath()+"nanguamache";
// String cacheDirPath = getCacheDir().getAbsolutePath()+Constant.APP_DB_DIRNAME;
Log.i("xiao", "cacheDirPath="+cacheDirPath);
//设置数据库缓存路径
cwv.getSettings().setDatabasePath(cacheDirPath);
//设置 Application Caches 缓存目录
cwv.getSettings().setAppCachePath(cacheDirPath);
//开启 Application Caches 功能
cwv.getSettings().setAppCacheEnabled(true);
Config.init(this.getActivity());
//url
cwv.loadUrl("http://write.blog.youkuaiyun.com/postedit/46045297");
}
public void startActivityForResult(CordovaPlugin command, Intent intent,
int requestCode) {
this.activityResultCallback = command;
this.activityResultKeepRunning = this.keepRunning;
// If multitasking turned on, then disable it for activities that return
// results
if (command != null) {
this.keepRunning = false;
}
// Start activity
super.startActivityForResult(intent, requestCode);
}
@Override
public void setActivityResultCallback(CordovaPlugin plugin) {
this.activityResultCallback = plugin;
}
@Override
public Activity getActivity() {
// TODO Auto-generated method stub
return this;
}
@Override
public Object onMessage(String id, Object data) {
// TODO Auto-generated method stub
return null;
}
@Override
public ExecutorService getThreadPool() {
// TODO Auto-generated method stub
return threadPool;
}
}