Android模拟器打开失败: ENOENT (No such file or directory)

标签 android file android-emulator storage android-permissions

我需要有关在 Android 模拟器中保存文件的权限的帮助...我已添加

<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中

我的保存文件代码:

   if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        imageView.setImageBitmap(imageBitmap);
   }

        String root = Environment.getExternalStorageDirectory().toString();


        File myDir = new File(root + "/Img");
        myDir.mkdirs();
        long n = System.currentTimeMillis();
        String fname = "IMG_" + n + ".jpeg";
        file = new File(myDir, fname);
        if (file.exists())
            file.delete();
        try {
            FileOutputStream out2 = new FileOutputStream(file);// here fire exception
            imageBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out2); 
            out2.flush();
            out2.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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" />

有什么想法吗?

最佳答案

解决方案是从 Nougat 降级为 KitKat!感谢您的建议

关于Android模拟器打开失败: ENOENT (No such file or directory),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39819128/

相关文章:

android - 在 Firebase/Android 聊天应用程序中发送和接收大图像文件的最佳方法是什么

android - 在 Android 中做全屏图像 slider 的最佳方式(如 Android Gallery)

php - 如何在 ubuntu 服务器中创建 .sql 文件?

java - 读取文件并检查行是否等于字符串

android - 如何修复慢速 Android 模拟器?

android - API 级别低于 14 的 ShareActionProvider

linux - 如何在 linux 中保存没有扩展名的文件?

java - 无法在父级或祖先上下文中找到方法

Android 模拟器无法与 Xamarin/Visual Studio Mac 配合使用

android - Xamarin firebase 不同的 google-services.json 用于不同的构建配置