3

我在 android 10 中共享图像时遇到问题。我收到此错误:

java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.my.app.provider/external_files/Downloads/96732_9f726aea1ca9566cb0ab4846a8e1bcd8.jpg from pid=13435, uid=1000 需要导出提供程序, 或 grantUriPermission()

我应该迁移到范围存储但我不知道如何迁移的问题。我是初学者。这是我的代码:

public class ShareTask extends AsyncTask <String, String, String> {
    String path;
    File file;
    private Context context;
    private ProgressDialog pDialog;

    public ShareTask(Context context) {
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub

        super.onPreExecute ();

        pDialog = new ProgressDialog (context);
        pDialog.setMessage ("Downloading ...");
        pDialog.setIndeterminate (false);
        pDialog.setCancelable (false);
        pDialog.show ();

    }

    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
        path = args[0];
        String idStr = path.substring (path.lastIndexOf ('/') + 1);
        File filepath = Environment.getExternalStorageDirectory ();
        File dir = new File (filepath.getAbsolutePath () + "/Downloads/");
        dir.mkdirs ();
        String fileName = idStr;
        file = new File (dir, fileName);
        Ion.with (getApplicationContext ()).load (path)
                .write (file);
        return null;
    }

    @Override
    protected void onPostExecute(String args) {
        // TODO Auto-generated method stub

        Intent share = new Intent (Intent.ACTION_SEND);
        share.setType ("image/gif");
        share.putExtra (Intent.EXTRA_STREAM, FileProvider.getUriForFile (SlideImageActivity.this, BuildConfig.APPLICATION_ID + ".provider", file));

        // SHARE URL
        startActivity (Intent.createChooser (share, "Share the photo"));
        pDialog.dismiss ();
    }
}
}
4

0 回答 0