添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
B4X is a set of simple and powerful cross platform RAD tools:
  • B4A (free) - Android development
  • B4J (free) - Desktop and Server development
  • B4i - iOS development
  • B4R (free) - Arduino, ESP8266 and ESP32 development
  • All developers, with any skill level, are welcome to join the B4X community .

    Android Question How to get FileProvider working without entire RuntimePermission lib or entire com.android.support:support-v4 ?

    I need my app to be able to update itself, but also be as small as possible.
    I also don't want my app to require permission to the user's storage/files, so I am using FileProvider.
    The FileProvider class uses the function "GetSafeDirDefaultExternal" to get a directory that the shared file can be placed. This function is included in the RuntimePermission lib but including that lib adds 500k to my app. So, I found an alternative way to get that the same directory value using javaobject in this thread: https://www.b4x.com/android/forum/t...-value-without-runtimepermissions-lib.144955/
    But it appears that in order to use the FileProvider class in needs some extra support class(es) that are also linked into the app when the RuntimePermission lib is an included lib, which again adds 500k to the app.
    I was then able to eliminate the need for the RuntimePermission lib by including the below line:
    But this also adds like 500k to the app.
    Then I found out that it seems the only class I really need to get fileprovider working is "android.support.v4.content.FileProvider".
    So, is there a way that I can just include that single class without having to include the entire "com.android.support:support-v4" ?
    I provide Custom Hardware and Software Solutions to Help Automate a Business to Reduce Costs and Increase Productivity.
    If any of my posts were helpful, please consider a donation of any amount ... or clicking on the Solution Vote or the Like button would be appreciated too. :)
    FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.omnisoft.vpndot-9oJauvaJ5BkLPB51S-hXAw==/base.apk"],nativeLibraryDirectories=[/data/app/com.omnisoft.vpndot-9oJauvaJ5BkLPB51S-hXAw==/lib/arm64, /system/lib64, /product/lib64]]
    I provide Custom Hardware and Software Solutions to Help Automate a Business to Reduce Costs and Increase Productivity.
    If any of my posts were helpful, please consider a donation of any amount ... or clicking on the Solution Vote or the Like button would be appreciated too. :)
    FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.omnisoft.vpndot-9oJauvaJ5BkLPB51S-hXAw==/base.apk"],nativeLibraryDirectories=[/data/app/com.omnisoft.vpndot-9oJauvaJ5BkLPB51S-hXAw==/lib/arm64, /system/lib64, /product/lib64]]
    not sure if any of this will help, but
    your android.support.v4.content.FileProvider seems to have been replaced by androidx.core.content.FileProvider
    an .aar is available from maven
    the FileProvider class is in there and is looking for a lot of things. am attaching the full source for the fileprovider class only. if it can be built alone, you'll have your class.
    i'm working on another project which is looking for many of the same imports. you have to find them first, and even then they depend on even more stuff.

    Attachments

    "A little kindness - as little as required by applicable law."
    "It can't hurt to read the thread before replying."
    "Show code; code always does what you tell it to do, not always what you tell us it does."
    "building a class" is getting beyond my lower-level knowledge of android.
    So, please don't spend a lot of time for a solution just for me.
    But if your work on your other project allows for an easy solution for my issue, then that would be great :)
    I provide Custom Hardware and Software Solutions to Help Automate a Business to Reduce Costs and Increase Productivity.
    If any of my posts were helpful, please consider a donation of any amount ... or clicking on the Solution Vote or the Like button would be appreciated too. :)
    "A little kindness - as little as required by applicable law."
    "It can't hurt to read the thread before replying."
    "Show code; code always does what you tell it to do, not always what you tell us it does."
    <provider android:name="b4a.tinyfileprovider.igolub.B4AFileProvider" 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" />
    FATAL EXCEPTION: main
    Process: com.mycompany.myapp, PID: 11631
    java.lang.RuntimeException: Unable to get provider b4a.tinyfileprovider.igolub.B4AFileProvider: java.lang.ClassNotFoundException: Didn't find class "b4a.tinyfileprovider.igolub.B4AFileProvider" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/lib/arm64, /system/lib64, /product/lib64]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
        at EdHooker_42b8453bf7df105343083f1377c32094be493c49.hook(Unknown Source:120)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "b4a.tinyfileprovider.igolub.B4AFileProvider" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/lib/arm64, /system/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6972)
        ... 11 more
    I provide Custom Hardware and Software Solutions to Help Automate a Business to Reduce Costs and Increase Productivity.
    If any of my posts were helpful, please consider a donation of any amount ... or clicking on the Solution Vote or the Like button would be appreciated too. :)
    FATAL EXCEPTION: main
    Process: com.mycompany.myapp, PID: 11631
    java.lang.RuntimeException: Unable to get provider b4a.tinyfileprovider.igolub.B4AFileProvider: java.lang.ClassNotFoundException: Didn't find class "b4a.tinyfileprovider.igolub.B4AFileProvider" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/lib/arm64, /system/lib64, /product/lib64]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
        at EdHooker_42b8453bf7df105343083f1377c32094be493c49.hook(Unknown Source:120)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "b4a.tinyfileprovider.igolub.B4AFileProvider" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-S_hdK65qQLVXHYzPxhY2MA==/lib/arm64, /system/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6972)
        ... 11 more
    My Bad, I forgot to include your new lib in the project (normally I would get a compile error reminding me to do that).
    So, it compiled OK now - I will test it now....
    I provide Custom Hardware and Software Solutions to Help Automate a Business to Reduce Costs and Increase Productivity.
    If any of my posts were helpful, please consider a donation of any amount ... or clicking on the Solution Vote or the Like button would be appreciated too. :)
    If UseFileProvider = False Then Dim uri As JavaObject Return uri.InitializeStatic("android.net.Uri").RunMethod("parse", Array("file://" & File.Combine(SharedFolder, FileName))) Dim f As JavaObject f.InitializeNewInstance("java.io.File", Array(SharedFolder, FileName)) Dim fp As JavaObject Dim context As JavaObject context.InitializeContext 'fp.InitializeStatic("android.support.v4.content.FileProvider") fp.InitializeStatic("b4a.tinyfileprovider.igolub.B4AFileProvider") '<-------- changed to new class name Return fp.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f)) End If End Sub
    I provide Custom Hardware and Software Solutions to Help Automate a Business to Reduce Costs and Increase Productivity.
    If any of my posts were helpful, please consider a donation of any amount ... or clicking on the Solution Vote or the Like button would be appreciated too. :)
    If UseFileProvider = False Then Dim uri As JavaObject Return uri.InitializeStatic("android.net.Uri").RunMethod("parse", Array("file://" & File.Combine(SharedFolder, FileName))) Dim f As JavaObject f.InitializeNewInstance("java.io.File", Array(SharedFolder, FileName)) Dim fp As JavaObject Dim context As JavaObject context.InitializeContext 'fp.InitializeStatic("android.support.v4.content.FileProvider") fp.InitializeStatic("b4a.tinyfileprovider.igolub.B4AFileProvider") '<-------- changed to new class name Return fp.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f)) End If End Sub You didn't fully read my post. You don't need an additional file provider. Delete the file provider class and just use TinyFileProvider. It contains all the methods from the FileProvider class...
    Dim tp As TinyFileProvider
    tp.GetFileUri(.....)
    I provide Custom Hardware and Software Solutions to Help Automate a Business to Reduce Costs and Increase Productivity.
    If any of my posts were helpful, please consider a donation of any amount ... or clicking on the Solution Vote or the Like button would be appreciated too. :)
    This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies. Accept Learn more…