0

So I'm working on an app for android and I've gotten it to work as long as it's been created using aspose cells. Here is my code:

class Home: Fragment(R.layout.fragment_home) {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view: View = inflater.inflate(R.layout.fragment_home, container, false)

        val load = view.findViewById<Button>(R.id.button3)
        val new = view.findViewById<Button>(R.id.button4)
        val editText = view.findViewById<EditText>(R.id.editTextTextPersonName)

        new.setOnClickListener(View.OnClickListener {
            Excel.name = "${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx"
            Excel.workbook = Workbook()
            Excel.workbook!!.save(Excel.name)
            println("Created: ${Excel.workbook}")
        })

        load.setOnClickListener(View.OnClickListener {
            Excel.workbook = Workbook("${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx")
            Excel.name = "${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx"
            Excel.workbook!!.save("${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx")
            println("Loaded: ${Excel.workbook}")
        })
        return view
    }
}

the problem is when I try to download a .xlsx file and load it, it gives me this error:

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

I'm not sure why this is happening. Any help would be awesome! Thanks!

EDIT: Here's my AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.FRCScout22"
        tools:targetApi="31">
        <activity
            android:name=".DropDownActivity"
            android:exported="false">
            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>

</manifest>
  • I think you need to have proper read/write permissions or have full permissions to the external storage. So, kindly do the needful. See the following threads for your reference. https://stackoverflow.com/questions/74252061/java-io-filenotfoundexception-storage-emulated-0-download-joueurs-xlsx-open-f, https://stackoverflow.com/questions/23527767/open-failed-eacces-permission-denied and https://github.com/captain-miao/AndroidException/issues/7 PS. I am working as Support developer/ Evangelist at Aspose. – Amjad Sahi Nov 10 '22 at 18:16
  • @AmjadSahi, so I've added to the OP what I added to the code but it still didn't work. The weird thing is that when I create the file with the app, it loads fine, but when I download another file, it throws the error. –  Nov 10 '22 at 18:58

0 Answers0