Android IOException: open failed: EACCES (Permission denied)

I have some code that updates the ID3 tags of a song. It works fine for files inside device storage, but gives "java.io.IOException: open failed: EACCES (Permission denied)" message for files in external storage. I also set the WRITE_EXTERNAL_STORAGE permission in the manifest, but it didn't help. by providing my code below, any help would be appreciated.

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();
}

      

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

      

My log: -

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

      

+3


source to share


1 answer


So I figured, from KITKAT onwards, Android does not allow full access to the external card for apps even after using the permission. So the code is really good, but we need to find another way to deal with the situation. As soon as I receive it, be sure to let others know!



+1


source







All Articles