我正在用cordova开发一个android APP,我想每天创建一个文件夹并在其中存储一个txt文件。我尝试的一切都适用于每个 android 的内部存储器,但不适用于外部 SD 卡,看看并帮助我,
if(sDeviceVersion=='4.0' || sDeviceVersion=='4.0.4'){ var sPath = 'file:///storage/extSdCard/'; }else if(sDeviceVersion=='4.1' || sDeviceVersion=='4.1.2' ||sDeviceVersion=='4.3.1'){ var sPath = 'file:///storage/extSdCard/'; }else if(sDeviceVersion=='4.4' || sDeviceVersion=='4.4.4'){ var sPath = 'file:///storage/extSdCard/'; }else if(sDeviceVersion=='5.0' || sDeviceVersion=='5.1.1'){ var sPath = 'file:///mnt/sdcard/'; // }else if(sDeviceVersion=='6.0' || sDeviceVersion=='6.0.1'){ var sPath = 'file:///storage/sdcard1/'; }else if(sDeviceVersion=='7.0' || sDeviceVersion=='7.1.2'){ var sPath = 'file:///storage/sdcard1/'; }
以上条件一直有效到 4.4.4 版本,5.0 之后 PATH 不正确。
我已经为 /mnt 和 /storage 尝试了以下所有这些路径
// sdcard0 works on all the androind for Internal Memory
// 'file:///storage/sdcard1/'; suppose to work for external in higher version but
// 'file:///mnt/sdcard/'; it works but in Internal memory ERROR
// externalSdCard -----> Not found with mnt and storage
// SECONDARY_STORAGE
// 'file:///storage/UsbDriveB/' -----------> didn't worked
// external_sd is not worked with storage and mnt
我到处都读到 sdcard0 是内部的而 sdcard1 是外部的,但它似乎不再工作了。谁能帮我解决问题。
我也试过了
alert(cordova.file.externalRootDirectory); // file:///storage/sdcard0/ Internal memory alert(cordova.file.externalApplicationStorageDirectory); // path to file:///android/data... alert(cordova.file.dataDirectory); // file:///data/androind/data/... alert(cordova.file.externalDataDirectory); // file://storage/sdcard0/android/data/...
以上所有仅适用于内部存储。
所有对外部存储的存储/读取/写入权限。
最佳答案
从 Android 5.0 开始,外部(可移动)SD 的位置不再是固定路径。而是在路径中使用 SD 卡的序列号。
例如,在运行 Android 7.1.1 的三星 Galaxy S4 上,物理外部可移动 SD 卡路径为 /storage/4975-1401/ .
此外,外部 SD 卡的根目录(例如 /storage/4975-1401/)现在对 Android 应用程序是只读的。这意味着如果您的应用需要写入 SD 卡,则必须在应用沙箱目录(例如 /storage/4975-1401/Android/data/your.app.package.id/files)中进行。
cordova-plugin-file不允许您访问外部(可移动)SD 卡:例如 cordova.file.externalRootDirectory返回 file:///storage/emulated/0/ .
但是,您可以使用 getExternalSdCardDetails()的 cordova-diagnostic-plugin检索外部(可移动)SD 卡的文件路径,例如:
function getExternalSdLocation(done){
cordova.plugins.diagnostic.getExternalSdCardDetails(function(details){
details.forEach(function(detail){
if(detail.type == "application"){
cordova.file.externalSdCardApplicationDirectory = detail.filePath;
}else if(detail.type == "root"){
cordova.file.externalSdCardRootDirectory = detail.filePath;
}
});
done();
}, function(error){
console.error(error);
done();
});
}
getExternalSdLocation(function(){
// use cordova.file.externalSdCardApplicationDirectory to write to SD card
});
对于 Android 6.0 及以上版本,需要运行时权限才能访问外部 SD 卡。 您可以使用 requestRuntimePermission()在 cordova-diagnostic-plugin请求此权限。
function requestExternalSdPermission(done){
cordova.plugins.diagnostic.requestRuntimePermission(function(status){
switch(status){
case cordova.plugins.diagnostic.permissionStatus.GRANTED:
console.log("Permission granted");
getExternalSdLocation(done);
break;
case cordova.plugins.diagnostic.permissionStatus.DENIED:
console.log("Permission denied");
askAgain(done);
break;
case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
console.log("Permission permanently denied");
reportError(done);
break;
}
}, function(error){
console.error("The following error occurred: "+error);
reportError(done);
}, cordova.plugins.diagnostic.permission.WRITE_EXTERNAL_STORAGE);
}
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />在AndroidManifest.xml - 参见 Android permissions .关于android - 适用于 Android 5.1.1 及更高版本的 Cordova 的外部存储路径(SD 卡),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45770040/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm
当我使用has_one时,它工作得很好,但在has_many上却不行。在这里您可以看到object_id不同,因为它运行了另一个SQL来再次获取它。ruby-1.9.2-p290:001>e=Employee.create(name:'rafael',active:false)ruby-1.9.2-p290:002>b=Badge.create(number:1,employee:e)ruby-1.9.2-p290:003>a=Address.create(street:"123MarketSt",city:"SanDiego",employee:e)ruby-1.9.2-p290
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我正在使用带有Rails的Devise,我想添加一个方法“getAllComments”,所以我这样写:classUser在我的Controller中:defdashboard@user=current_user@comments=@user.getAllComments();end当我访问我的url时,我得到了undefinedmethod`getAllComments'for#我做错了什么?谢谢 最佳答案 因为getAllComments是一个类方法,而您正试图将其作为实例方法访问。您要么需要访问它:User.getAllCom
我正在使用Rails3.2.3和Ruby1.9.3p0。我发现我经常需要确定某个字符串是否出现在选项列表中。看来我可以使用Ruby数组.includemethod:或正则表达式equals-tildematchshorthand用竖线分隔选项:就性能而言,一个比另一个好吗?还有更好的方法吗? 最佳答案 总结:Array#include?包含String元素,在接受和拒绝输入时均胜出,对于您的示例只有三个可接受的值。对于要检查的更大的集合,看起来Set#include?和String元素可能会获胜。如何测试我们应该根据经验对此进行测试
Ruby初学者努力简单地将这个@@people散列的值打印到控制台classPerson#haveafirst_nameandlast_nameattributewithpublicaccessorsattr_accessor:first_nameattr_accessor:last_name#haveaclassattributecalled`people`thatholdsanarrayofobjects@@people=[]#havean`initialize`methodtoinitializeeachinstancedefinitialize(first_name,last_
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:AmazonAPIlibraryforPython?我正在寻找一个AmazonAPI,它可以让我:按书名或作者查找书籍显示书籍封面获取有关每本书的信息(价格、评级、评论数、格式、页数等)Python或Ruby库都可以(我只想要最容易使用的库)。有什么建议么?我知道在SO上还有其他一些关于此的帖子,但这些API似乎很快就过时了。[几个月前我尝试了几个建议的Ruby库,但无法让它们中的任何一个工作。]
我刚刚看到whitehouse.gov正在使用drupal作为CMS和门户技术。drupal的优点之一似乎是很容易添加插件,而且编程最少,即重新发明轮子最少。这实际上正是Ruby-on-Rails的DRY理念。所以:drupal的缺点是什么?Rails或其他基于Ruby的技术有哪些不符合whitehouse.org(或其他CMS门户)门户技术的资格? 最佳答案 Whatarethedrawbacksofdrupal?对于Ruby和Rails,这确实是一个相当主观的问题。Drupal是一个可靠的内容管理选项,非常适合面向社区的站点。它
怎样说才是明智的呢?if@thing=="01"or"02"or"03"or"04"or"05"(数字包含在数据类型字符串的列中。) 最佳答案 制作数组并使用.include?if["01","02","03","04","05"].include?(@thing)如果值真的都是连续的,你可以使用像(1..5).include?这样的范围对于字符串,你可以使用:if("01".."05").include?(@thing) 关于ruby-优雅的链式'or'用于测试Ruby中的相同变量,我