mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Fixed image sharing to other apps
This commit is contained in:
parent
d8cbe480ad
commit
036457117c
2 changed files with 40 additions and 12 deletions
|
@ -104,6 +104,8 @@ public class BrowserFragment extends CustomFragment {
|
||||||
pendingUrl = null;
|
pendingUrl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webView.setParentActivity(getActivity());
|
||||||
|
|
||||||
this.setRetainInstance(true);
|
this.setRetainInstance(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,22 +123,48 @@ public class ContextMenuWebView extends NestedWebView {
|
||||||
|
|
||||||
case ID_SHARE_IMAGE:
|
case ID_SHARE_IMAGE:
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
|
boolean writeToStoragePermitted = true;
|
||||||
new ImageDownloadTask(null, local.getPath()) {
|
if (android.os.Build.VERSION.SDK_INT >= 23) {
|
||||||
@Override
|
int hasWRITE_EXTERNAL_STORAGE = parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||||
protected void onPostExecute(Bitmap result) {
|
if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
|
||||||
Uri myUri = Uri.fromFile(new File(local.getPath()));
|
writeToStoragePermitted = false;
|
||||||
Intent sharingIntent = new Intent();
|
if (!parentActivity.shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
sharingIntent.setAction(Intent.ACTION_SEND);
|
new AlertDialog.Builder(parentActivity)
|
||||||
sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
|
.setMessage(R.string.permissions_image)
|
||||||
sharingIntent.setType("image/png");
|
.setPositiveButton(context.getText(android.R.string.yes), new DialogInterface.OnClickListener() {
|
||||||
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
@Override
|
||||||
context.startActivity(Intent.createChooser(sharingIntent, "Share image using"));
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 23)
|
||||||
|
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||||
|
MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(context.getText(android.R.string.no), null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||||
|
MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
|
||||||
}
|
}
|
||||||
}.execute(url);
|
}
|
||||||
|
if (writeToStoragePermitted) {
|
||||||
|
final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
|
||||||
|
new ImageDownloadTask(null, local.getPath()) {
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Bitmap result) {
|
||||||
|
Uri myUri = Uri.fromFile(new File(local.getPath()));
|
||||||
|
Intent sharingIntent = new Intent();
|
||||||
|
sharingIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
|
||||||
|
sharingIntent.setType("image/png");
|
||||||
|
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
context.startActivity(Intent.createChooser(sharingIntent, "Share image using"));
|
||||||
|
}
|
||||||
|
}.execute(url);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_IMAGE_EXTERNAL_BROWSER:
|
case ID_IMAGE_EXTERNAL_BROWSER:
|
||||||
|
|
Loading…
Reference in a new issue