alann-maulana / share_whatsapp

A Flutter plugin to share content from your Flutter app to the WhatsApp share dialog.
MIT License
1 stars 8 forks source link

PlatformException ERROR_SHARE Failed to find configured root that contains #8

Open myxzlpltk opened 3 months ago

myxzlpltk commented 3 months ago

Few months ago it was working fine. But suddenly its throw error like this

D/SHARE_WHATSAPP(12181): method=installed, argument=com.whatsapp.w4b
D/SHARE_WHATSAPP(12181): method=installed, argument=com.whatsapp
D/SHARE_WHATSAPP(12181): method=share, argument={file=/storage/emulated/0/Download/1721356034505.png, phone=6285156922642, packageName=com.whatsapp, text=null, contentType=image/png}
D/SHARE_WHATSAPP(12181): Cache file path : /data/data/{{package}}/cache/share_whatsapp/1721356034505.png
[SendReceiptMain] start
PlatformException (PlatformException(ERROR_SHARE, Failed to find configured root that contains /data/data/{{package}}/cache/share_whatsapp/1721356034505.png, java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/{{package}}/cache/share_whatsapp/1721356034505.png
                  at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:867)
                  at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:467)
                  at id.my.alan.share_whatsapp.ShareWhatsappPlugin.share(ShareWhatsappPlugin.kt:159)
                  at id.my.alan.share_whatsapp.ShareWhatsappPlugin.onMethodCall(ShareWhatsappPlugin.kt:91)
                  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
                  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
                  at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
                  at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
                  at android.os.Handler.handleCallback(Handler.java:938)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:264)
                  at android.app.ActivityThread.main(ActivityThread.java:8315)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
                  , null))
niceumang-tech commented 2 months ago

Hello, @myxzlpltk

To resolve this issue,

=> Add below into android > main > res > xml folder (if not available then create new) => create new .xml file with named 'provider_paths' under the xml folder and paste below code

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-files-path name="external_files" path="."/>
    <external-path
        name="external"
        path="." />
    <cache-path
        name="cache"
        path="." />
    <external-cache-path
        name="external_cache"
        path="." />
    <files-path
        name="files"
        path="." />
</paths>

=> Now add below code into you AndroidManifest.xml file

<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

Issue is Resolved!!

Happy Coding!