Hello all,
I have been trying to create function to share files to other app with below codes :
I have include FileProvider library as required and here are my manifest :
I got these errors :
What did i do wrong?... it seems to work with file sharing example from erel.. https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/
I have been trying to create function to share files to other app with below codes :
B4X:
'******************************************************
'SHARE FILE - WHATSAPP ETC
'******************************************************
Sub TW_File_ShareFile(strFilename As String)
Dim strFilename As String = "b4a.png"
File.Copy(File.DirAssets, strFilename, Provider.SharedFolder, strFilename) '<<----- error already occur here!
bla...bla...bla...
End Sub
I have include FileProvider library as required and here are my manifest :
B4X:
'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="5" android:targetSdkVersion="30"/>
<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.LightTheme)
'End of default text.
AddPermission(android.PERMISSION_READ_PHONE_STATE)
AddPermission(android.Permissions_CALL_PHONE)
AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
'************SHARE FUNCTION REQUIRED BELOW ****************
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 got these errors :
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
tw_system_tw_file_sharefile (java line: 117)
java.io.FileNotFoundException: b4a.png: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:342)
at TW.System.tw_system._tw_file_sharefile(tw_system.java:117)
at TW.System.b4xmainpage._btnsharefile_click(b4xmainpage.java:358)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7590)
at android.view.View.performClickInternal(View.java:7546)
at android.view.View.access$3900(View.java:842)
at android.view.View$PerformClick.run(View.java:28933)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8306)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8186)
at libcore.io.IoBridge.open(IoBridge.java:478)
... 20 more
tw_system_tw_file_sharefile (java line: 117)
java.io.FileNotFoundException: b4a.png: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:342)
at TW.System.tw_system._tw_file_sharefile(tw_system.java:117)
at TW.System.b4xmainpage._btnsharefile_click(b4xmainpage.java:358)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7590)
at android.view.View.performClickInternal(View.java:7546)
at android.view.View.access$3900(View.java:842)
at android.view.View$PerformClick.run(View.java:28933)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8306)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8186)
at libcore.io.IoBridge.open(IoBridge.java:478)
... 20 more
What did i do wrong?... it seems to work with file sharing example from erel.. https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/