Android emulator打开失败:enoint(没有这样的文件或目录)
我需要有关在Android emulator中保存文件权限的帮助。。。我补充说Android emulator打开失败:enoint(没有这样的文件或目录),android,file,android-emulator,storage,android-permissions,Android,File,Android Emulator,Storage,Android Permissions,我需要有关在Android emulator中保存文件权限的帮助。。。我补充说 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-feature android:name="android.hardware
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera" android:required="true" />
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.denis.calculator">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".InfoActivity"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera" android:required="true" />
有什么想法吗?请替换下面的行
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Img");
与
同时从代码中删除以下行
if (file.exists())
file.delete();
因为你定义文件名的方式永远不会有相同的文件名。因此,在这里验证文件的存在是无关紧要的
如果您的应用程序将用于Android 6.0或更高版本,您还必须向用户申请书面许可。有关详细信息,请参阅以下链接:
您可以使用我最近创建的库中定义的解决方案,该库包括一个权限演示
稍后我将通过Maven使其可用,但现在您必须在项目中导入droidlibx库模块 解决方案是将牛轧糖降级为KitKat!感谢您的建议您到底有什么异常?打开失败:enoint(没有这样的文件或目录)删除此行
if(file.exists())file.delete()代码>仍然不起作用:/n您在真正的设备上尝试过吗?此问题是否仅在emulator上发生?仍然没有:/n在这一行上,跳转以捕获FileOutputStream out2=新FileOutputStream(文件);是的,我有。。关于nexus:/您可以在手机上使用file explorer应用程序并检查是否在根目录中创建了此Img目录吗?看起来没有。您必须通过参考我的答案中的链接在应用程序中添加权限请求者模型。仅在清单上定义它对Android操作系统发布的棉花糖、牛轧糖和future one是不起作用的。目前的解决方案将只工作到棒棒糖OS。您可以通过创建一个针对棒棒糖操作系统的模拟器来测试emulator。是的!!此解决方案无法继续工作,并且可能会在新操作系统上对应用程序的行为产生歧义。
File myDir = new File(Environment.getExternalStorageDirectory(),"Img");
if (file.exists())
file.delete();