Android IOException:打开失败:EACCES(权限被拒绝)

时间:2015-08-01 14:38:54

标签: android permissions ioexception android-permissions

我有一个更新歌曲ID3标签的代码,它适用于设备存储内的文件,但为外部存储中的文件提供“java.io.IOException:open failed:EACCES(Permission denied)”错误。我也在清单中设置了WRITE_EXTERNAL_STORAGE权限但没有帮助。 提供下面的代码,任何帮助都会得到满足。

protected void EditTags(final Song song,String tite, String album, String artist){
    File src = new File(song.getPath());
    MusicMetadataSet src_set = null;
    try {
        src_set = new MyID3().read(src);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } // read metadata

    if (src_set == null) // perhaps no metadata
    {
        Log.i("NULL", "NULL");
    }
    else
    {
        try{
            IMusicMetadata metadata = src_set.getSimplified();
            String artist1 = metadata.getArtist();
            String album1 = metadata.getAlbum();
            String song_title = metadata.getSongTitle();
            Number track_number = metadata.getTrackNumber();
            Log.i("artist", artist1);
            Log.i("album", album1);
        }catch (Exception e) {
            e.printStackTrace();
        }

        MusicMetadata meta = new MusicMetadata("name");
        meta.setAlbum(tite);
        meta.setArtist(artist);
        meta.setAlbum(album);
        try {
            new MyID3().update(src, src_set, meta);
            Toast.makeText(context, "Tags Updated", Toast.LENGTH_SHORT).show();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ID3WriteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  // write updated metadata
    }
    scanner=new MediaScannerConnection(context,
            new MediaScannerConnection.MediaScannerConnectionClient() {

                public void onScanCompleted(String path, Uri uri) {
                    scanner.disconnect();
                }

                public void onMediaScannerConnected() {
                    scanner.scanFile(song.getPath(), "audio/*");
                }
            });

    scanner.connect();
}

我的AndroidManifest.xml: -

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.musicplayer" >

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    >
   .
   .
</application>
</manifest>

我的日志: -

08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ java.io.IOException: open failed: EACCES (Permission denied)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at java.io.File.createNewFile(File.java:941)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at java.io.File.createTempFile(File.java:1006)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at org.cmc.music.myid3.MyID3.update(MyID3.java:60)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at com.musicplayer.AlbumSongAdapter.EditTags(AlbumSongAdapter.java:280)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at com.musicplayer.AlbumSongAdapter$3.onClick(AlbumSongAdapter.java:240)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:160)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5254)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
08-01 12:02:55.388    8085-8085/com.musicplayer W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
08-01 12:02:55.389    8085-8085/com.musicplayer W/System.err﹕ Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
08-01 12:02:55.389    8085-8085/com.musicplayer W/System.err﹕ at libcore.io.Posix.open(Native Method)
08-01 12:02:55.389    8085-8085/com.musicplayer W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
08-01 12:02:55.389    8085-8085/com.musicplayer W/System.err﹕ at java.io.File.createNewFile(File.java:934)
08-01 12:02:55.389    8085-8085/com.musicplayer W/System.err﹕ ... 12 more

1 个答案:

答案 0 :(得分:1)

所以我想出来,从KITKAT开始,Android即使在使用权限之后也不允许完全外部卡访问应用程序。所以代码实际上很好,但我们需要找到解决问题的另一种方法。一旦我得到它,肯定会让其他人知道!