Android Question Problem with FileProvider

Reminisce

Active Member
I am trying to open a pdf on my app using an external app. I am using B4XPages.

I tried the file provider example provided in https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/ and my app crashes immediately after the installation.

A quick check on the unfiltered logs came up with this.
Log:
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f090011
    at android.app.ActivityThread.installProvider(ActivityThread.java:6284)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:5847)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5764)
    at android.app.ActivityThread.-wrap1(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1691)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6549)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f090011
    at android.content.res.ResourcesImpl.getResourcePackageName(ResourcesImpl.java:266)
    at android.content.res.Resources.getResourcePackageName(Resources.java:1949)
    at com.google.android.gms.common.internal.StringResourceValueReader.<init>(com.google.android.gms:play-services-basement@@17.4.0:5)
    at com.google.firebase.FirebaseOptions.fromResource(FirebaseOptions.java:156)
    at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:244)
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1919)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1894)
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
    at android.app.ActivityThread.installProvider(ActivityThread.java:6281)
    ... 10 more
crashInfo.exceptionClassName = android.content.res.Resources$NotFoundException , crashInfo.exceptionMessage = Unable to find resource ID #0x7f090011, crashInfo.throwFileName = ResourcesImpl.java,crashInfo.throwLineNumber = 266
updateDefaultTypefaceI fontHash = 7faa816b55a3fd7dc9c80a3adde95b69ba1a6d602a1c9ab04eec84f66ed010f5
 fontPath = /data/typeface/default/7faa816b55a3fd7dc9c80a3adde95b69ba1a6d602a1c9ab04eec84f66ed010f5
Already set agent. fontPath:/data/typeface/default/7faa816b55a3fd7dc9c80a3adde95b69ba1a6d602a1c9ab04eec84f66ed010f5 fontHash:7faa816b55a3fd7dc9c80a3adde95b69ba1a6d602a1c9ab04eec84f66ed010f5
updateDefaultTypefaceI fontHash = 7faa816b55a3fd7dc9c80a3adde95b69ba1a6d602a1c9ab04eec84f66ed010f5

My Manifest Code:
'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="21" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)

SetApplicationAttribute(android:usesCleartextTraffic, "true")   
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)

CreateResourceFromFile(Macro,FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro,FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro,FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile(Macro,FirebaseAdMob.FirebaseAds)
AddReplacement($ADMOB_APP_ID$, ca-app-pub-7399xxxxxxxxxxxxxxxxxxxxxx)

'End of default text.
SetActivityAttribute(Main, android:theme, "@style/DarkTheme")
CreateResource(values, theme.xml,
<resources>
    <style
        name="DarkTheme" parent="@android:style/Theme.Material.Light.NoActionBar.Fullscreen">
          <item name="android:windowBackground">@color/window</item>
    </style>
</resources>
)
CreateResource(values, colors.xml,
<resources>
    <color name="window">#ffffff</color>
</resources>
)


CreateResource(values-v21, themes.xml,
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
<item name="android:colorPrimary">#FF00415D</item>
<item name="android:colorPrimaryDark">#FF00415D</item>
<item name="android:colorAccent">#FF00415D</item>
</style>
</resources>)

SetApplicationAttribute(android:theme,"@style/MyAppTheme")
CreateResource(values,themes.xml,
<resources>
<style name = "MyAppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
</style>
</resources>
)


AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="18" />
)

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

Code to view pdf:
        pdfname = "1.pdf"
        Dim FileName As String = pdfname
        File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName)
        Dim in As Intent
        in.Initialize(in.ACTION_VIEW, "")
        Starter.Provider.SetFileUriAsIntentData(in, FileName)
        'Type must be set after calling SetFileUriAsIntentData
        in.SetType("application/pdf*")
        StartActivity(in)

Please I need a solution, Thanks.
 

Jim Brown

Active Member
Licensed User
Longtime User
Looks like a similar problem I was having. Here's what I did:
B4X:
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "1.pdf") ' <-- or URI to file
in.Flags=1 ' READ PERMISSION
in.SetComponent("android/com.android.internal.app.ResolverActivity")
in.SetType("application/pdf")
StartActivity(in)
 
Upvote 0

Reminisce

Active Member
I willc
Looks like a similar problem I was having. Here's what I did:
B4X:
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "1.pdf") ' <-- or URI to file
in.Flags=1 ' READ PERMISSION
in.SetComponent("android/com.android.internal.app.ResolverActivity")
in.SetType("application/pdf")
StartActivity(in)
Thanks man. I'll try it. The problem is The app crashes immediately I launch it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. The code above will not work.
2. Firebase has nothing to do with FileProvider.
3. Run the example as-is. If it doesn't work then your SDK is misconfigured.
 
Upvote 0
Top