Flutter-Advanced-Share icon indicating copy to clipboard operation
Flutter-Advanced-Share copied to clipboard

Share Image work only once.

Open jmall opened this issue 6 years ago • 11 comments

This works perfect, but only for the first time the app is launched. When I try the second time, I am getting an error (In gmail for instance) 'couldn't attach file' If I kill the App and restart, the sharing works again only once. Why?

jmall avatar Jun 20 '18 16:06 jmall

yess i'm too.. share image work only once...

gofur avatar Jul 19 '18 03:07 gofur

I'm experiencing the same thing. This is the exception that is printed to console:

java.lang.SecurityException: Permission Denial: reading android.support.v4.content.FileProvider uri content://com.example.my_app.adv_provider/cache_files/1533772610.png from pid=1196, uid=10117 requires the provider be exported, or grantUriPermission

SocratesDz avatar Aug 09 '18 00:08 SocratesDz

Same here, this needs fixing, it's useless without the fix. There is PR #4 that should fix this issue, however it did not work for me anyway, unfortunately. It works 100 % in emulator, but on my device (Xiaomi Mi A1) it crashes same as for the other guys.

maral avatar Sep 24 '18 16:09 maral

Same problem with me. The solution only works twice.

My temporary fix is to store the image separately in external storage instead of using the cached one.

adiranas avatar Oct 03 '18 22:10 adiranas

same ..

lizhuoyuan avatar Dec 04 '18 08:12 lizhuoyuan

@lizhuoyuan @adiranas @jmall @gofur Hi, you can try a edit that for me fix the problem?

`public int share(Map params) { this.params = params; fileHelper = getFileHelper(params);

    if (checkKey("title")) {
        title = (String) params.get("title");
    }

    if (checkKey("msg")) {
        intent.putExtra(Intent.EXTRA_TEXT, (String) params.get("msg"));
    }

    if (checkKey("subject")) {
        intent.putExtra(Intent.EXTRA_SUBJECT, (String) params.get("subject"));
    }

    if (checkKey("url")) {
        if (fileHelper.isFile()) {
            List<ResolveInfo> resInfoList = registrar.context().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                registrar.context().grantUriPermission(packageName, fileHelper.getUri(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }

            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.putExtra(Intent.EXTRA_STREAM, fileHelper.getUri());
            intent.setType(fileHelper.getType());
        }
    }
    return 0;
}`

find and replace the share method of Base.java class. for me work, i will want a confirm from yuo. thank you

juani21 avatar Dec 07 '18 18:12 juani21

@juani21 Also works for me, thank you!

It would be perfect if you could share it with facebook and instagram.

lizhuoyuan avatar Dec 08 '18 04:12 lizhuoyuan

Where to place this Share() method in a flutter and i am using this method

AdvancedShare.generic(msg: message, url: base64ImageUrl).then((response) {
handleResponse(response);
});

MistryHiral avatar Jan 22 '19 11:01 MistryHiral

@lizhuoyuan @adiranas @jmall @gofur Hi, you can try a edit that for me fix the problem?

`public int share(Map params) { this.params = params; fileHelper = getFileHelper(params);

    if (checkKey("title")) {
        title = (String) params.get("title");
    }

    if (checkKey("msg")) {
        intent.putExtra(Intent.EXTRA_TEXT, (String) params.get("msg"));
    }

    if (checkKey("subject")) {
        intent.putExtra(Intent.EXTRA_SUBJECT, (String) params.get("subject"));
    }

    if (checkKey("url")) {
        if (fileHelper.isFile()) {
            List<ResolveInfo> resInfoList = registrar.context().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                registrar.context().grantUriPermission(packageName, fileHelper.getUri(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }

            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.putExtra(Intent.EXTRA_STREAM, fileHelper.getUri());
            intent.setType(fileHelper.getType());
        }
    }
    return 0;
}`

find and replace the share method of Base.java class. for me work, i will want a confirm from yuo. thank you

@juani21 where is the Base.java file is located in the flutter project please

shyjuzz avatar Apr 03 '19 07:04 shyjuzz

facing the same issue, anyone found the solution??

yatindeokar avatar May 04 '19 16:05 yatindeokar

@shyjuzz follow the path Base.java

giandifra avatar May 04 '19 17:05 giandifra