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;
|
||||
}
|
||||
|
||||
webView.setParentActivity(getActivity());
|
||||
|
||||
this.setRetainInstance(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -123,6 +123,30 @@ public class ContextMenuWebView extends NestedWebView {
|
|||
|
||||
case ID_SHARE_IMAGE:
|
||||
if (url != null) {
|
||||
boolean writeToStoragePermitted = true;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 23) {
|
||||
int hasWRITE_EXTERNAL_STORAGE = parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
|
||||
writeToStoragePermitted = false;
|
||||
if (!parentActivity.shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
new AlertDialog.Builder(parentActivity)
|
||||
.setMessage(R.string.permissions_image)
|
||||
.setPositiveButton(context.getText(android.R.string.yes), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (writeToStoragePermitted) {
|
||||
final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
|
||||
new ImageDownloadTask(null, local.getPath()) {
|
||||
@Override
|
||||
|
@ -136,9 +160,11 @@ public class ContextMenuWebView extends NestedWebView {
|
|||
context.startActivity(Intent.createChooser(sharingIntent, "Share image using"));
|
||||
}
|
||||
}.execute(url);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ID_IMAGE_EXTERNAL_BROWSER:
|
||||
|
|
Loading…
Reference in a new issue