【发布时间】:2017-02-26 19:42:42
【问题描述】:
需要帮助
我正在尝试通过长按照片从 webview 下载照片, 当我用敬酒消息测试长按动作时,它起作用了
但它没有下载。
private View.OnLongClickListener listener=new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
mWebView.setDownloadListener(new DownloadListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Name of your downloadble file goes here, example: Keerthi");
DownloadManager dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
dm.enqueue(request);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important!
intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE
intent.setType("*/*");//any application,any extension
Toast.makeText(getContext(), "Downloading File", //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
}
});
return true;
}
};
【问题讨论】:
-
希望对您有所帮助 - stackoverflow.com/questions/16091393/…
标签: android image webview download long-press