I have been using Erl's method of sending emails with files attached for several years now.
I had earlier converted all but one of my apps to b4xpages and had no trouble converting the FS92 class that sends these emails.
I just started converting the last app to b4xpages and have gotten hung up on converting my FS92 routine. The file.copy step is crashing with the log show below.
The logic in the program in question is as follows. The starter.fs92helpfile variable was used to display the "Help" screen with a txt message in another 'class'. It displays and the user touches the help menu and 'Send to Email' so I know it is in DirAssets correctly. I also displayed the name in the log as shown in the log above. I added the logs to try and debug.
The manifest is set up as recommended in Erl's "FileProvider' Example:
I have the definition of FileProvider in Starter as:
I can't tell from the log error whether the problem is in the source file or in the shared folder output file.
I am a little suspicious of the '0' in the file.copy error message. It might imply that it doesn't know the name of the app and therefore can't find the file. I checked and my app is named in 'Main' in the same way it is named in the programs that worked.
I might also mention that the file.copy worked fine in the original b4a program.
I did find I was using a 'filehandler' class in other programs. I brought that in, but it didn't help.
Thanks for any help. Cliff McKibbin
[class] FileProvider - share files
Edit: FileProvider is included as an internal library now. After investigating several issues with the current FileProvider code that you can find in the forum, I decided to make some improvements and implement it in a class. Starting from Android 7 (API 24) you cannot directly share file uris...
www.b4x.com
I had earlier converted all but one of my apps to b4xpages and had no trouble converting the FS92 class that sends these emails.
I just started converting the last app to b4xpages and have gotten hung up on converting my FS92 routine. The file.copy step is crashing with the log show below.
B4X:
sending message to waiting queue of uninitialized activity (submitjob)
*** Receiver (httputils2service) Receive (first time) ***
FileName1:tsrel.txt ' this is a log line I am writing to try and debug-see logic below
Copying:tsrel.txt ' ditto
pagefs92_sendfile (java line: 262)
java.io.FileNotFoundException: /data/user/0/b4a.CoOpSupportx/files/shared/tsrel.txt (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:287)
at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:342)
at b4a.CoOpSupportx.pagefs92._sendfile(pagefs92.java:262)
at b4a.CoOpSupportx.pagefs92._b4xpage_menuclick(pagefs92.java:138)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA$1.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6958)
at java.lang.reflect.Method.invoke(Native Method)
The logic in the program in question is as follows. The starter.fs92helpfile variable was used to display the "Help" screen with a txt message in another 'class'. It displays and the user touches the help menu and 'Send to Email' so I know it is in DirAssets correctly. I also displayed the name in the log as shown in the log above. I added the logs to try and debug.
B4X:
' This logic provided by Erl in his "FileProvider" example and uses the library "FileProvider"
Dim FileName1 As String = Starter.FS92File
Log ("FileName1:" & FileName1)
If Starter.FS92Switch =2 Then
Log ("Copying:" & FileName1)
File.Copy(File.DirAssets, FileName1, Starter.Provider.SharedFolder, FileName1)
Log ("Copy successful")
End If
The manifest is set up as recommended in Erl's "FileProvider' Example:
B4X:
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
AddManifestText (<uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION"/>)
AddManifestText (<uses-permission android:name = "android.permission.ACCESS_COARSE_LOCATION"/>)
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" />
I have the definition of FileProvider in Starter as:
B4X:
Sub Process_Globals
' setup File Provider for email
Public Provider As FileProvider
....
End Sub
Sub Service_Create
Provider.Initialize
....
end sub
I can't tell from the log error whether the problem is in the source file or in the shared folder output file.
I am a little suspicious of the '0' in the file.copy error message. It might imply that it doesn't know the name of the app and therefore can't find the file. I checked and my app is named in 'Main' in the same way it is named in the programs that worked.
I might also mention that the file.copy worked fine in the original b4a program.
I did find I was using a 'filehandler' class in other programs. I brought that in, but it didn't help.
Thanks for any help. Cliff McKibbin