Android Question [Solved]Can't save Excel file

Theera

Expert
Licensed User
Longtime User
Refer to this I 've download the excel example,and run it ,it 's not Ok. about saving.
[Qoate]
An error has occurred in sub:main$ResumableSub_SaveTable_Clickresume(java line:579)
java.io.FileNotFoundException:/storage/emulatated/0/1.xls:eek:pen failed:EPERM(Operation not permitted)
[/Qoate]

so then I added the permission code as belows,but it's still error
B4X:
    For Each permission As String In Array(rp.PERMISSION_WRITE_EXTERNAL_STORAGE, rp.PERMISSION_READ_EXTERNAL_STORAGE)
        rp.CheckAndRequest(permission)
        Wait For Activity_PermissionResult (permission As String, Result As Boolean)
        If Result = False Then
            ToastMessageShow("No permission!", True)
            Activity.Finish
            Return
        End If
    Next
 

Attachments

  • ExcelExample.zip
    13.3 KB · Views: 38
Solution
If your app will not be published on Google Play then modify the Manifest like this
B4X:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>
If you need to set TargetSdkVersion to 30+ then you can use this other method
https://www.b4x.com/android/forum/t...cess-internal-external-storage-sdk-30.130411/
But only if you will not publish on Google Play.
If you need to publish on Google Play I think that you could use this method
https://www.b4x.com/android/forum/t...-save-and-load-external-files.132731/#content

DonManfred

Expert
Licensed User
Longtime User
whenever you see File.DirRootExternal you know it is a broken code
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
whenever you see File.DirRootExternal you know it is a broken code
Should I do for solved this problem.I'm sorry that I don't understand your words how to solved.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
If your app will not be published on Google Play then modify the Manifest like this
B4X:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>
If you need to set TargetSdkVersion to 30+ then you can use this other method
https://www.b4x.com/android/forum/t...cess-internal-external-storage-sdk-30.130411/
But only if you will not publish on Google Play.
If you need to publish on Google Play I think that you could use this method
https://www.b4x.com/android/forum/t...-save-and-load-external-files.132731/#content
 
Upvote 0
Solution

Theera

Expert
Licensed User
Longtime User
Thank you for kind of you, Sagenut , Don Manfred and Agraham . I have finished.
I have edited some Agraham's code from another experts'
B4X:
Private Sub GetPackageName As String
    #If B4A
    Return Application.PackageName
    #Else If B4I
    Dim no As NativeObject
    no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
    Dim name As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleIdentifier"))
    Return name
    #Else If B4J
    Dim joBA As JavaObject
    joBA.InitializeStatic("anywheresoftware.b4a.BA")
    Return joBA.GetField("packageName")
    #End If
End Sub
 

Attachments

  • ExcelExample2.zip
    15.4 KB · Views: 44
Upvote 0
Top