java.io.IOException:open failed:EACCES(权限被拒绝)[MainfestPermission已设置]

时间:2017-07-31 20:09:28

标签: java android file-handling java-io

我在这个论坛上看到了这个问题一百遍.... 答案是:

  

写下行:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  

到您的AndroidMainfest.xml

这总是排名最高的答案!

所以我这样做了,但我仍然得到了例外......(我的例外登录结束)

AndroidMainfest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.niton.photoviewer">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".AlbumActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Aktion Call:

public void save() {
        try {
            System.out.println("Try save Album on : "+Environment.getExternalStorageDirectory().toString()+"/Albs");
            File f = new File(new File(Environment.getExternalStorageDirectory(),"Albs"),"Album_"+(System.currentTimeMillis()/500)+".alb");
            f.createNewFile();
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
            oos.writeObject(this);
            System.out.println("Success save Album "+f.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

我知道权限是正确放置的,因为: Screenshot with permission

LOG:

07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: Set The Value
07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: Try save Album on : /mnt/sdcard/Albs
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err: java.io.IOException: open failed: EACCES (Permission denied)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at java.io.File.createNewFile(File.java:940)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at com.niton.photoviewer.Album.save(Album.java:33)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at com.niton.photoviewer.AlbumActivity.createAlbum(AlbumActivity.java:311)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at com.niton.photoviewer.AlbumActivity.onAcceptTextInput(AlbumActivity.java:127)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at com.niton.photoviewer.AlbumActivity.onClick(AlbumActivity.java:110)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at java.lang.reflect.Method.invoke(Method.java:511)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at android.view.View.performClick(View.java:4084)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at android.view.View$PerformClick.run(View.java:16966)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at android.os.Handler.handleCallback(Handler.java:615)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at android.os.Looper.loop(Looper.java:137)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at java.lang.reflect.Method.invoke(Method.java:511)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at dalvik.system.NativeStart.main(Native Method)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err: Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at libcore.io.Posix.open(Native Method)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:     at java.io.File.createNewFile(File.java:933)
07-31 19:53:54.744 20408-20408/com.niton.photoviewer W/System.err:  ... 18 more
07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: There are no saved albs
07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: Generate Album : All
07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: Only add to row : All
07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: Cover : android.support.constraint.ConstraintLayout@a7910d48
07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: Generate Album : Album Name
07-31 19:53:54.744 20408-20408/com.niton.photoviewer I/System.out: Cancel!

0 个答案:

没有答案