Android Question [class] FileProvider - share files Question

Azhar

Active Member
Licensed User
Longtime User
Re: This thread post 4

Hi All, this sharing of a text file works great but I now need to be able to read that same text file to save on the device.
So what I do with this code provided by Erel is just select the share to Google Drive option.
Now I just need to be able to do a 'file pick' of the same text file to download it (onto another device) to be used by the same app (in the case a user upgrades their phone etc)
Is there some ready-made class or code available to do this?

Thanks,

Azhar
 

Azhar

Active Member
Licensed User
Longtime User
Thanks Erel,

I'm on to that now but how do I force ContentChooser to look only at a specific file name Eg: userSettings.txt for example?

B4X:
Sub btnRestore_Click
    cs.Show("*/*.txt", "select userSettings.txt file")
    
    
End Sub
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
In Android 8.1 (Oppo AX5s) this supplied FilerProvider class works great. I can choose any cloud drive that is currently set up on the device to upload to. Then I have managed to write the code to download this back and all is great.
But on another phone (Samsung S8+) running Android version 9, after I click on the Backup button, all that I'm presented with is a phone vibration asking to "Bring the other device close to share the content' message - via Bluetooth I guess. That's all I get. I am not presented with the usual target directory picker like I am in Android v 8.1.

File Provider Code - I've only changed it to upload a list:
Sub btnBackup_Click
    Dim recCounter As Int = 0
    Dim rowRec As String

    'load the zikr file line by line into zikrList
    Dim zikrList As List
    
    'read the whole contents of the current live zikr file into list
    zikrList.Initialize
    zikrList = File.ReadList(File.DirInternal,"userZikr.txt")
    
    Dim in As Intent
    
    File.WriteList(Starter.Provider.SharedFolder, FileToSend, zikrList)
    in.Initialize(in.ACTION_SEND, "")
    in.SetType("text/plain")
    in.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri(FileToSend))
    in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
    StartActivity(in)
End Sub

This is the Manifest if that helps...
Manifest Editor:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
AddPermission(android.permission.ACCESS_NOTIFICATION_POLICY)
'this is new for backup and restore
AddManifestText(<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
)

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)


Has the maxSDKVersion="18" got anything to do with it?

Thanks,

Azhar
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
Hi Erel,

Thanks so much. Removing it caused a crash but changing it to in.SetType("*/*") worked successfully.
I'm so glad this user data backup/restore to/from cloud storage was painless in the end.

Thanks again for your help.

Azhar
 
Upvote 0
Top