【发布时间】:2017-11-17 00:36:13
【问题描述】:
我已经创建了一个代码来保存来自 webview 的图像。代码有效,但有一些问题,这里是代码
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;
}
});
}
}
当我尝试长按图像时,它会显示对话框消息以保存图像,当我单击它时,它将显示 toast 消息,说 图像已成功保存,是的我的统计栏中的通知
问题是,当我尝试打开我的画廊并搜索图像时,我永远找不到图像,因为它没有保存到我的本地存储中。
你能帮我修复代码吗? 谢谢
【问题讨论】:
-
我读了这篇文章,stackoverflow.com/questions/3474448/… 但是如何将此代码添加到我的代码中?
-
任何人请帮忙,我需要这个代码
标签: android image webview save local-storage