尽管提供了 许可,File.canWrite()在某些设备上返回false。虽然提供了WRITE_EXTERNAL_STORAGE权限,但File.canWrite()在某些设备上返回false
在我的应用程序需要将数据写入到外置SD卡。然而,这在一些设备上工作,但是在其他一些设备上失败 。 例如 作品:Limebox内部闪存,SD卡,Android操作系统:2.3.3 三星SD卡,extSdcard,Android操作系统:4.0.3
失败:Leoxys SD卡,extsd Android操作系统:4.0.3
如何找到动态的Android兼容设备,例如 ,它们允许外部SD卡写入操作。 myfile.canWrite
详情: 的getExternalSD()是一个用户定义的功能,其将返回外部SD卡路径
在我的情况外部SD卡路径是“/ MNT/extSdcard”(或)“/ MNT/extsd” 我通过阅读文件中查找外部SD卡路径‘/system/etc/vold.fstab’
下面是一些代码片段:它会在外部SD卡的文件夹。 在某些设备上,myfile.canWrite()返回FALSE,我无法创建文件夹。
String sdcardpath = getExternalSD();
System.out.println("the sdcard path is:"+sdcardpath.trim().toString());
tv = (TextView) findViewById(R.id.textView1);
tv.append("the sd card path is:"+sdcardpath);
File myfile = new File(sdcardpath);
tv.append("\n the extsd is readable or not:"+myfile.canRead());
tv.append("\n \n the extsd is writable or not:"+myfile.canWrite());
if(myfile.canWrite()){
File testfile = new File(sdcardpath, "test");
if(testfile.exists()){
}else{
boolean mkdir = testtlie.mkdirs();
if(mkdir == true){
tv.append("\n\n the path is:"+sdcardpath.trim().toString()+"/myfile");
}else{
tv.append("\n File does not have permissions");
}
}
}else{
System.out.println("the external sd card does not have write permissions");
tv.append("\n\n the external sd card does not have write permissions");
}
xml文件片段。
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
我想获得
一个建议。是否有任何API可让开发人员知道设备是否与Android完全兼容? b。为什么在不同的硬件设备上有不同的行为。这与固件有关吗?
c。有没有其他方法可以在这种硬件上实现写入?
我alreday尝试下/系统的/ etc/premissions /使用终端模拟器 修改文件“platform.xml”的权限,但我不能写模式
默认情况下,Android提供环境中打开该文件。 getEnternalStorageDirectory()。 但库返回“到/ mnt/SD卡”,这将是在一些器件中的内部存储器。
您的意见将不胜感激!
其实,即使有一个SD卡 – TimothyP