MertcanDinler / Flutter-Advanced-Share

Flutter plugin for sharing
MIT License
32 stars 23 forks source link

Share Image work only once. #2

Open jmall opened 6 years ago

jmall commented 6 years ago

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?

gofur commented 6 years ago

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

SocratesDz commented 6 years ago

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
maral commented 6 years ago

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.

adiranas commented 6 years ago

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.

lizhuoyuan commented 5 years ago

same ..

juani21 commented 5 years ago

@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

lizhuoyuan commented 5 years ago

@juani21 Also works for me, thank you!

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

MistryHiral commented 5 years ago

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);
});
shyjuzz commented 5 years ago

@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

yatindeokar commented 5 years ago

facing the same issue, anyone found the solution??

giandifra commented 5 years ago

@shyjuzz follow the path Base.java