我已经设置了以下我的Android清单:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)
我的活动中有以下内容:
File sd = Environment.getExternalStorageDirectory();
boolean can_write = sd.canWrite();
Run Code Online (Sandbox Code Playgroud)
sd返回/ mnt/sdcard
我在我的设备上测试(evo 3d)而不是模拟器.SD卡已安装.它只在充电模式和没有插入usb电缆时发生.Google上的各种页面和堆栈上的帖子显示完全相同的方法来检查SD卡是否可写,所以我必须丢失一些东西.
更新:
我尝试以下代码,并抛出ioexception权限被拒绝.
File TestFile = new File(sd + "/testfile.txt");
try {
boolean result = TestFile.createNewFile();
if(result)
{
Log.i("tag","successfully created file");
} else {
Log.i("tag","failed to create file");
}
} catch (IOException e) {
Log.e("tag",e.toString() + " " + TestFile);
return false;
}
Run Code Online (Sandbox Code Playgroud)
我已经格式化了我的SD卡,重新安装它,并重新启动了手机,但仍然有同样的错误.
UPDATE
显然,这是我自己的无知导致它失败.我的权限阻止在我的清单的错误部分.再次感谢 :)
我正在尝试在jquery插件中使用.proxy()方法.不知道发生了什么,但它不是在调用methods.strobe.我有以下示例代码:
(function($) {
var settings = {
}
var methods = {
init: function(options) {
alert('init fired');
$.proxy(methods.strobe,this);
return this;
},
destroy: function() {
},
strobe: function(){
alert('strobe fired');
},
show: function() {},
hide: function() {},
refresh: function() {}
};
$.fn.notify = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.notify');
}
}; …Run Code Online (Sandbox Code Playgroud)