我正在为我的移动网站添加一些移动应用程序特定的功能。目前,该应用程序或多或少只是一个包装器。
public class Activity extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
if (this.isOnline()) {
super.loadUrl("http://mysite.com");
} else {
super.loadUrl("file:///android_asset/www/offline.html");
}
}
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
}
以下javascript出现了问题。如果我替换 super.loadUrl("http://mysite.com"); 使用 super.loadUrl("file:///android_asset/www/online.html") 并在那里运行以下javascript,它工作正常。但是如果我在 mysite.com 上运行它,它会继续抛出以下异常:
07-13 12:25:12.762: E/Web Console(28251): 不允许加载本地资源: file:///data/data/com.my.app/.Pic.jpg?1342171460960 at null:0
对我做错了什么有任何想法吗?
var camera = (function(){
var camera = {
settings : {
quality: 50,
}
};
var error = function(message) {
console.error("Error happened while trying to get a picture", message);
};
document.addEventListener("deviceready", function() {
camera.settings.destinationType = navigator.camera.DestinationType.FILE_URI;
camera.fromPhone = function() {
this.settings.sourceType = navigator.camera.PictureSourceType.CAMERA;
return this;
};
camera.fromLibrary = function() {
this.settings.sourceType = navigator.camera.PictureSourceType.PHOTOLIBRARY;
return this;
};
camera.get = function(callback) {
navigator.camera.getPicture(callback, error, camera.settings);
};
}, false);
return camera;
})();
//Later, at a click event
camera.fromPhone().get(function(imageURI){
alert("imageURI" + imageURI)
$("#largeImage").attr("src", imageURI);
});