Reputation: 31
I have a problem with sharing images in android 10. I get this error:
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 requires the provider be exported, or grantUriPermission()
The problem that I should migrate to scoped storage but I don't know how. I am a beginner. this is my code:
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 ();
}
}
}
Upvotes: 3
Views: 152