i already create a code to save image from webview. the code works but there are some problem, here is the code
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
final WebView.HitTestResult result = mWebView.getHitTestResult();
if (result.getType() == WebView.HitTestResult.IMAGE_TYPE ||
result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
//menu.setHeaderTitle(result.getExtra());
menu.add(0, 1, 0, "Save Image")
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
String DownloadImageURL = result.getExtra();
if(URLUtil.isValidUrl(DownloadImageURL)){
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(DownloadImageURL));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.enqueue(request);
Toast.makeText(getContext(),"Image save successfully.",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getContext(),"Error to save image.",Toast.LENGTH_SHORT).show();
}
return false;
}
});
}
}
when i try to long click the image it will show dialog message to save the image, when i click on it, it will show toast message that says the image have been save succesfully and yes there a notification in my stat bar
the problem is, when i try to open my gallery and search for the image, i never find the image because it's not save to my local storage.
can you help me to fix the code? thanks