Android Question FileProvider Not Working

rscheel

Well-Known Member
Licensed User
Longtime User
I'm trying to use FileProvider to send an email with an attachment in my application, the FileProvider example works, but when integrating the code to my app does not work, I think it's a problem with appCompat, I leave the error code and my manifest

This line for working appcompat

B4X:
#Extends: android.support.v7.app.AppCompatActivity

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="14" android:targetSdkVersion="28"/>
<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.DarkTheme)
'End of default text.

'Tema Aplicación
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#00796b</item>
        <item name="colorPrimaryDark">#004d40</item>
        <item name="colorAccent">#00796b</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.Material</item>
        <item name="asp_preferenceIconTint">?colorAccent</item>
        <item name="asp_preferenceDialogIconTint">?asp_preferenceIconTint</item>
        <item name="windowActionModeOverlay">true</item>
    </style>
</resources>)


'************ File Provider ****************
'E-Mail senden ab Android 6+
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" />
)
'Ende of File Provider

B4X:
java.lang.RuntimeException: Unable to start activity ComponentInfo{cl.deschile.rodal/cl.deschile.rodal.main}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.ContentFrameLayout.setId(int)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3107)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3250)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1947)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7032)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.ContentFrameLayout.setId(int)' on a null object reference
    at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:703)
    at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:457)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:145)
    at cl.deschile.rodal.main.onCreate(main.java:61)
    at android.app.Activity.performCreate(Activity.java:7327)
    at android.app.Activity.performCreate(Activity.java:7318)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3087)
    ... 11 more

Thanks
 

rscheel

Well-Known Member
Licensed User
Longtime User
The error has nothing to do with FileProvider.
The error happens when I add the FileProvider code to the manifest

B4X:
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" />
)
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
Please upload a small project with AppCompat and FileProvider.

Dear Erel, I was doing tests and compile in my coputer that I develop daily, which I am using the Android Studio SDK, to my surprise there is no error that occurs when compiling on my computer that I am using the SDK installer that comes with B4A, I think some component is missing in the installed SDK, since the libraries on both computers are the same.

I'm not sure what component is missing.

Greetings.
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
@Erel I have noticed another problem, but apparently it is with the hide, when you place the code in the manifest you have to save the changes and close b4a and reopen, that way it does not throw the error. I use the version of B4A v9.0
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
@Erel I have noticed another problem, but apparently it is with the hide, when you place the code in the manifest you have to save the changes and close b4a and reopen, that way it does not throw the error. I use the version of B4A v9.0
You are doing something wrong. The manifest code should be updated when you close the manifest editor or when you save it. If something doesn't work then clean the project (Ctrl + P).
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
You are doing something wrong. The manifest code should be updated when you close the manifest editor or when you save it. If something doesn't work then clean the project (Ctrl + P).

Thanks Erel
 
Upvote 0
Top