Android Question FileProvider Not Working

Discussion in 'Android Questions' started by rscheel, May 21, 2019.

  1. rscheel

    rscheel Well-Known Member Licensed 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

    Code:
    #Extends: android.support.v7.app.AppCompatActivity
    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=
    "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
    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The error has nothing to do with FileProvider.
     
  3. rscheel

    rscheel Well-Known Member Licensed User

    The error happens when I add the FileProvider code to the manifest

    Code:
    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" />
    )
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please upload a small project with AppCompat and FileProvider.
     
  5. rscheel

    rscheel Well-Known Member Licensed User

    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.
     
  6. rscheel

    rscheel Well-Known Member Licensed 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
     
  7. Erel

    Erel Administrator Staff Member Licensed 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).
     
  8. rscheel

    rscheel Well-Known Member Licensed User

    Thanks Erel
     
Loading...
  1. 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.
    Dismiss Notice