PhrotonX
Member
In the code below, I could not be able to use FileProvider because simply adding that library into my project causes my app to crash on an Android 15 emulator and my physical Android 10 device.
Also, I have no idea on how could I open some files located within a subfolder (in this case, m_fileRepository.DIRECTORY is "/attachments/" of type String) without using RuntimePermissions or FileProvider because both libraries make my app crash by simply enabling them.
I am currently on B4A version 13.10 64-bit and Android SDK 34.
My manifest:
My Libraries:
The error log from the ADB logcat if I enabled FileProvider library and opened the application:
Also, I have no idea on how could I open some files located within a subfolder (in this case, m_fileRepository.DIRECTORY is "/attachments/" of type String) without using RuntimePermissions or FileProvider because both libraries make my app crash by simply enabling them.
I am currently on B4A version 13.10 64-bit and Android SDK 34.
B4X:
Public Sub OpenAttachment(attachment_id As Long)
Dim filePath As String = File.Combine(File.DirInternal & m_fileRepository.DIRECTORY, GetAttachment(attachment_id).GetFilename)
Log(filePath)
Dim intentObj As Intent
intentObj.Initialize(intentObj.ACTION_VIEW, "file://" & filePath) ' Does not work.
intentObj.SetComponent("android/com.android.internal.app.ResolverActivity")
intentObj.SetType("*/*")
StartActivity(intentObj)
End Sub
B4X:
/data/user/0/com.cm.todolist/files/attachments/1744435111898_IMG_20250407_204849.jpg
Error occurred on line: 50 (AttachmentViewModel)
android.os.FileUriExposedException: file:///data/user/0/com.cm.todolist/files/attachments/1744435111898_IMG_20250407_204849.jpg exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:2265)
at android.net.Uri.checkFileUriExposed(Uri.java:2402)
at android.content.Intent.prepareToLeaveProcess(Intent.java:12524)
at android.content.Intent.prepareToLeaveProcess(Intent.java:12472)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1999)
at android.app.ContextImpl.startActivity(ContextImpl.java:1161)
at android.app.ContextImpl.startActivity(ContextImpl.java:1132)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:438)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:861)
at com.cm.todolist.attachmentviewmodel._openattachment(attachmentviewmodel.java:138)
at com.cm.todolist.editoractivity._clvattachments_itemclick(editoractivity.java:1333)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1114)
at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1077)
at b4a.example3.customlistview$ResumableSub_PanelClickHandler.resume(customlistview.java:805)
at b4a.example3.customlistview._panelclickhandler(customlistview.java:748)
at b4a.example3.customlistview._panel_click(customlistview.java:735)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:8028)
at android.view.View.performClickInternal(View.java:8005)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:31229)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8705)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
** Activity (editoractivity) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
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: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="24"
android:targetSdkVersion="34" />
<supports-screens android:largeScreens="true"
android:debuggable="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddManifestText(
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
AddManifestText(
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
AddManifestText(
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
CreateResource(xml, provider_paths,
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="root" path="" />
</paths>
)
#AdditionalJar: com.android.support:support-core-utils
'End of default text.
My Libraries:
The error log from the ADB logcat if I enabled FileProvider library and opened the application:
B4X:
04-12 18:33:39.903 24587 24587 D AndroidRuntime: Shutting down VM
04-12 18:33:39.908 24587 24587 E AndroidRuntime: FATAL EXCEPTION: main
04-12 18:33:39.908 24587 24587 E AndroidRuntime: Process: com.cm.todolist, PID: 24587
04-12 18:33:39.908 24587 24587 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.cm.todolist/com.cm.todolist.main}: java.lang.ClassNotFoundException: Didn't find class "com.cm.todolist.main" on path: DexPathList[[zip file "/data/app/~~n2cpsmOJ-ztPi0L3hFWv4Q==/com.cm.todolist-SraYYX9G8xE4wThrtu41Cw==/base.apk"],nativeLibraryDirectories=[/data/app/~~n2cpsmOJ-ztPi0L3hFWv4Q==/com.cm.todolist-SraYYX9G8xE4wThrtu41Cw==/lib/x86_64, /system/lib64, /system_ext/lib64]]
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3954)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4235)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:112)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2636)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:232)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.os.Looper.loop(Looper.java:317)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8705)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.cm.todolist.main" on path: DexPathList[[zip file "/data/app/~~n2cpsmOJ-ztPi0L3hFWv4Q==/com.cm.todolist-SraYYX9G8xE4wThrtu41Cw==/base.apk"],nativeLibraryDirectories=[/data/app/~~n2cpsmOJ-ztPi0L3hFWv4Q==/com.cm.todolist-SraYYX9G8xE4wThrtu41Cw==/lib/x86_64, /system/lib64, /system_ext/lib64]]
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:637)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.Instrumentation.newActivity(Instrumentation.java:1448)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3941)
04-12 18:33:39.908 24587 24587 E AndroidRuntime: ... 13 more
Last edited: