Android Question B4xPages + FileProvider

udg

Expert
Licensed User
Longtime User
Hi all,
I have a file in DirInternal and would like to mail it on user command.
Does this thread stiil apply at B4xPages time?
Do I simply need to move the FileProvider initialization from Starter to B4xMainPage? Or should I use Main for this?

Addition to manifest:
B4X:
AddManifestText(<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="19" />
)

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" />
)

Anyway, once the above is sorted out, will any common Android device be able to start an email intent? Or are there cases where this could fail (e.g. non Mail program on device)?
If the latter, what could be a B plan?

Thank you
 

udg

Expert
Licensed User
Longtime User
Use Try / Catch to catch the "no activity" error and show a message to the user.

Do you mean something like this?
B4X:
Dim in As Intent = email.GetIntent
in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
try
    StartActivity(in)
catch
    'If LastException.Message = "no activity" then ...
end try
Since I can't anticipate the real cause of fail (e.g. no "mail" app or mail app exists but not configured or anything else) wouldn't it be safer to show a generic message if the catch branch is taken, something like "mail couldn't be sent" (ok, it's no very informative but it signals the presence of a problem to investigate on..for those (hopefully) rare occasions where we should expect it to happen).

B4xPages: ok, thanks. I'll use B4xMainPage since it's the place where I already ask for other permissions.
 
Upvote 0
Top