Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting Permission Denial: reading com.zt.shareextend.ShareExtendProvider uri c #26

Open
kw2019ltd opened this issue Mar 23, 2020 · 22 comments

Comments

@kw2019ltd
Copy link

E/DatabaseUtils( 6372): java.lang.SecurityException: Permission Denial: reading com.zt.shareextend.ShareExtendProvider uri content://kw.ltd.sss.shareextend.fileprovider/root_path/data/data/kw.ltd.corovavirusapp/app_flutter/2020-03-23T16%3A56%3A26.803860.png from pid=6011, uid=1000 requires the provider be exported, or grantUriPermission()

i already applied

@9thwall
Copy link

9thwall commented Mar 24, 2020

Same here. Exact same issue on Android.
Watching thread for an answer.

@boring2
Copy link

boring2 commented Mar 26, 2020

me too.

@JEuler
Copy link
Contributor

JEuler commented Mar 26, 2020

Same issue, not working on Android.

@zhouteng0217
Copy link
Owner

@kw2019ltd @9thwall @boring2 @JEuler I did not find the issue on my device. Anyway , I updated some code on the version 1.1.2. Please update the version, try it and give me a feedback.

@5eeman
Copy link

5eeman commented Mar 31, 2020

Experiencing this issue on emulator (Pixel 3 / API 29). I'll try to check it on physical device.

@JEuler
Copy link
Contributor

JEuler commented Apr 2, 2020

Updated, but this issue still preserves. I will try to add native code changes and create a PR that will fix it.

@zhouteng0217
Copy link
Owner

@5eeman @JEuler ,could you give me some steps to reproduce the issue? I tried on emulator (Pixel 3 / API 29) and it still works well. So I need more detail info. Of course PR is welcome.

@JEuler
Copy link
Contributor

JEuler commented Apr 3, 2020

I'm just calling ShareExtend.share(path, 'image'); and getting this in logcat.
But sharing is working, BTW, I was confused by other issue, sharing works.

@JEuler
Copy link
Contributor

JEuler commented Apr 3, 2020

But to remove this warning one can use the following code:

List<ResolveInfo> resInfoList = mRegistrar.activity().getPackageManager().queryIntentActivities(chooserIntent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                mRegistrar.activity().grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }

I will try to create the PR anyway, but tommorow :) Happy isolated friday! 🍺

@JEuler
Copy link
Contributor

JEuler commented Apr 15, 2020

@kw2019ltd @9thwall @boring2 could you please check this PR? #28

You can try this PR version using this in your pubspec:

share_extend:
  git:
    url: https://github.com/JEuler/ShareExtend.git

@kw2019ltd
Copy link
Author

@JEuler its working fine with above PR.

pls file PR to master so it can be merged by admin

@JEuler
Copy link
Contributor

JEuler commented Apr 16, 2020

@kw2019ltd @zhouteng0217 #28 - it is already there :)

@JEuler
Copy link
Contributor

JEuler commented Apr 17, 2020

@kw2019ltd PR was merged, so the author will release new version a bit later.

@kw2019ltd
Copy link
Author

kw2019ltd commented Apr 17, 2020 via email

@shpy2001
Copy link

shpy2001 commented May 3, 2020

Still have this error on 1.1.5 .
If apply PR of JEuler for single file, it work well.

@JEuler
Copy link
Contributor

JEuler commented May 3, 2020

@zhouteng0217 Hm, please have a look at this issue.

@shpy2001
Copy link

shpy2001 commented May 6, 2020

I changed ShareExtendPlugin.java like this , and error gone:

`package com.zt.shareextend;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;

/**

  • Plugin method host for presenting a share sheet via Intent
    */
    public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, PluginRegistry.RequestPermissionsResultListener {

    /// the authorities for FileProvider
    private static final int CODE_ASK_PERMISSION = 100;
    private static final String CHANNEL = "com.zt.shareextend/share_extend";

    private final Registrar mRegistrar;
    private List list;
    private String type;
    private String sharePanelTitle;
    private String subject;
    ArrayList uriList = new ArrayList<>();

    public static void registerWith(Registrar registrar) {
    MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
    final ShareExtendPlugin instance = new ShareExtendPlugin(registrar);
    registrar.addRequestPermissionsResultListener(instance);
    channel.setMethodCallHandler(instance);
    }

    private ShareExtendPlugin(Registrar registrar) {
    this.mRegistrar = registrar;
    }

    @OverRide
    public void onMethodCall(MethodCall call, MethodChannel.Result result) {
    if (call.method.equals("share")) {
    if (!(call.arguments instanceof Map)) {
    throw new IllegalArgumentException("Map argument expected");
    }
    // Android does not support showing the share sheet at a particular point on screen.
    list = call.argument("list");
    type = call.argument("type");
    sharePanelTitle = call.argument("sharePanelTitle");
    subject = call.argument("subject");
    share(list, type, sharePanelTitle, subject);
    result.success(null);
    } else {
    result.notImplemented();
    }
    }

    private void share(List list, String type, String sharePanelTitle, String subject) {
    if (list == null || list.isEmpty()) {
    throw new IllegalArgumentException("Non-empty list expected");
    }
    Intent shareIntent = new Intent();
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

     if ("text".equals(type)) {
         shareIntent.setAction(Intent.ACTION_SEND);
         shareIntent.putExtra(Intent.EXTRA_TEXT, list.get(0));
         shareIntent.setType("text/plain");
     } else {
         if (ShareUtils.shouldRequestPermission(list)) {
             if (!checkPermission()) {
                 requestPermission();
                 return;
             }
         }
    
         
         for (String path : list) {
             File f = new File(path);
             Uri uri = ShareUtils.getUriForFile(getContext(), f);
             uriList.add(uri);
         }
    
         if ("image".equals(type)) {
             shareIntent.setType("image/*");
         } else if ("video".equals(type)) {
             shareIntent.setType("video/*");
         } else {
             shareIntent.setType("application/*");
         }
         if (uriList.size() == 1) {
             shareIntent.setAction(Intent.ACTION_SEND);
             shareIntent.putExtra(Intent.EXTRA_STREAM, uriList.get(0));
         } else {
             shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
             shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
         }
         
     }
     startChooserActivity(shareIntent, sharePanelTitle);
    

    }

    private Context getContext() {
    return mRegistrar.activity() != null ? mRegistrar.activity() : mRegistrar.context();
    }

    private void startChooserActivity(Intent shareIntent, String sharePanelTitle) {
    Intent chooserIntent = Intent.createChooser(shareIntent, sharePanelTitle);
    ShareUtils.grantUriPermission(getContext(), uriList, chooserIntent);
    if (mRegistrar.activity() != null) {
    mRegistrar.activity().startActivity(chooserIntent);
    } else {
    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mRegistrar.context().startActivity(chooserIntent);
    }
    }

    private boolean checkPermission() {
    return ContextCompat.checkSelfPermission(mRegistrar.context(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
    == PackageManager.PERMISSION_GRANTED;
    }

    private void requestPermission() {
    ActivityCompat.requestPermissions(mRegistrar.activity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, CODE_ASK_PERMISSION);
    }

    @OverRide
    public boolean onRequestPermissionsResult(int requestCode, String[] perms, int[] grantResults) {
    if (requestCode == CODE_ASK_PERMISSION && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    share(list, type, sharePanelTitle, subject);
    }
    return false;
    }
    }
    `

@JEuler
Copy link
Contributor

JEuler commented May 6, 2020

Maybe you can create a PR? :)

@shpy2001
Copy link

shpy2001 commented May 9, 2020

Maybe you can create a PR? :)

I tried but didn't know what to do !!! :(

@JEuler
Copy link
Contributor

JEuler commented May 9, 2020

Let's wait for @zhouteng0217 for the info about this issue. :)

@JEuler
Copy link
Contributor

JEuler commented May 17, 2020

@shpy2001 - so, you can just fork the repo, than you need to create pull request - if you need assistance - feel free to write me :)

@sgehrman
Copy link
Contributor

sgehrman commented May 29, 2020

#43

This seems to work. Please merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants