Georges GRESSIEN
Georges GRESSIEN

Reputation: 41

java.io.FileNotFoundException: /storage/emulated/0/Download/Joueurs.xlsx: open failed: EACCES (Permission denied)

I have a problem with some Android Phone with an error : java.io.FileNotFoundException: /storage/emulated/0/Download/Joueurs.xlsx: open failed: EACCES (Permission denied) I looked at solutions given by Stackoverflow. I changed my code and manifest but always had the same error. We have a problem with a Galaxy S21. In the parameter of it, it's not possible to change the permission setting to change the multimédia file to all files. It seems difficult to test this problem with the simulator
Have you an idea to solve this error Thank you very much for your help

Best regards

Georges

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.prod.gfer94"
android:minSdkVersion="8"
android:targetSdkVersion="19">

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"

 tools:ignore="ScopedStorage"/>
<application
    android:icon="@drawable/icogaef"
    android:label="@string/app_name"
    android:roundIcon="@drawable/icogaef"
    android:theme="@style/AppTheme"
    android:requestLegacyExternalStorage="true">
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="G.F.E.R94"
        android:textColor="@color/colorBleuDistrict">


    ImageButton BoutonLicencies = findViewById(R.id.imageButtonLicencies);
    BoutonLicencies.setOnClickListener(v -> {
        if (accesLicencies == 1){

            searchFile("Joueurs.xlsx");

            try {
                FileInputStream fileJoueur = null;
                if(!fileName.canRead())
                    fileName.setReadable(true);
                fileJoueur = new FileInputStream(fileName);
                XSSFWorkbook myWorkBook = null;
                myWorkBook =  new  XSSFWorkbook(fileJoueur);
                XSSFSheet mySheet = myWorkBook.getSheetAt(0);
                mySheet = myWorkBook.getSheetAt(0);
                Iterator<Row> rowIterator = mySheet.iterator();

Upvotes: 2

Views: 3093

Answers (2)

Georges GRESSIEN
Georges GRESSIEN

Reputation: 41

This is the code :

ActivityResultLauncher <Intent>  activityLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
            @Override
            public void onActivityResult(ActivityResult result) {
                if(result.getResultCode()== Activity.RESULT_OK) {
                    Intent dataExcel  = result.getData();
                    Uri uri = dataExcel.getData();
                    try {
                        inputStream = ImportActivity.this.getContentResolver().openInputStream(Uri.parse(uri.toString()));} catch (FileNotFoundException e) {
                        e.printStackTrace();}
                    try {
                        String excelPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
                        fileName = new File(excelPath, "Joueurs_copy.xlsx");
                        ActivityCompat.requestPermissions(ImportActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                PackageManager.PERMISSION_GRANTED);

                        FileUtils.copyToFile(inputStream, fileName);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    importPlayer();
                }
            }
        }
);

Upvotes: 0

Enes Sıtkı
Enes Sıtkı

Reputation: 1

Can you try add permission and provide full permission from the application information screen:

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

Upvotes: 0

Related Questions