Android Question [Solved] FileProvider.GetFileUri permissions

jcmartini

Member
Licensed User
Longtime User
I adapt, 1 1/2 year ago, a QR code reader application from the example found in the forum. Now i want to be able read a business card containg a QR code in vcf file mode. I found an example at https://www.b4x.com/android/forum/threads/insert-a-new-contact-with-a-qrcode-vcard.147894/. QR Code has been successfuly read and save to file in “fp.SharedFolder”, I believe. I get an abend in “fp.GetFileUri”. Maybe the problem is coming from the permissions I don’t give. No Manifest file example has been given in the example. Which permissions should I give in manifest file ?

B4X:
    Dim fp As FileProvider
    fp.Initialize
    File.WriteString(fp.SharedFolder, "vcard.vcf", s)
    Log("File vcard has been created...")
    
    'Insert in contacts
    Dim thisintent As Intent
    thisintent.Initialize(thisintent.ACTION_VIEW,fp.GetFileUri(fp.SharedFolder & "/vcard.vcf"))
    thisintent.SetType("text/x-vcard")
    thisintent.Flags = 0x01
    StartActivity(thisintent)
 

zed

Active Member
Licensed User
This code works correctly. No permission required
B4A:
' Creat vcf file
File.WriteString(Path, "vcard.vcf", YourValue)
    
' copy to SharedFolder
Dim fp As FileProvider
fp.Initialize
File.Copy(Path, "vcard.vcf", fp.SharedFolder, "vcard.vcf")
    
'Insert in contacts
Dim thisintent As Intent
thisintent.Initialize(thisintent.ACTION_VIEW,fp.GetFileUri("vcard.vcf"))
thisintent.SetType("text/x-vcard")
thisintent.Flags = 0x01
StartActivity(thisintent)
 
Upvote 0

jcmartini

Member
Licensed User
Longtime User
Why do you not write directly your file into fp. ShareFolder ?
What is your value of Path ?
Could you show me your manifest file ?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
we need more than "abend". what, exactly, was the exception thrown?

did you provide a fileprovider?
read this thread:
https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/
the fileprovider class is now part of b4a's internal libraries, but the example regarding how to create a fileprovider still applies.

one minor point: inventing a "success!" log message is not a good idea. if you really want to know if some i/o operation has been successfully carried out, you should use try/catch or - at the very least - test for the existence of the file. if the operation is actually successful, logging that it was successful is irrelevant (there would have been an abend otherwise). in other words, saying something was successful without actually testing for success will come back to bite you, especially in the event of null objects. there will be no error until some later point when you attempt to use the null object (which you didn't actually test when you had a chance, having preferred - instead - to log "success!")
 
Upvote 0

zed

Active Member
Licensed User
Upvote 0
Top