Android 从Webview下载.cer文件

Android 从Webview下载.cer文件,android,webview,Android,Webview,我想知道,因为2天,但无法修复它 我在WebView中打开了一个URL。 网站上有一个按钮,可以下载.cer文件 我的问题是当我点击按钮时,它开始下载文件并在通知栏中通知我 我正在尝试以下代码来完成此操作: DownloadManager.Request request = new DownloadManager.Request(Uri.parse(sourceURL)); // appears the same in Notification bar while downloading re

我想知道,因为2天,但无法修复它

我在
WebView
中打开了一个URL。 网站上有一个
按钮
,可以下载.cer文件

我的问题是当我点击
按钮时,它开始下载文件并在
通知栏中通知我

我正在尝试以下代码来完成此操作:

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(sourceURL));
// appears the same in Notification bar while downloading

request.setTitle("Downloading");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
//DownloadManager.Request request = new DownloadManager.Request(source);                        
manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
// Use the same file name for the destination
File destinationFile = new File(directory, "/Download/test.cer");

if (destinationFile.exists()) {
    destinationFile.delete();
}
request.setDestinationUri(Uri.fromFile(destinationFile));
// Add it to the manager
referencepath = manager.enqueue(request);
同样的情况也发生在设备的默认浏览器上,但我可以在 我在firefox浏览器中打开url

我还添加了权限

<!-- Permission so that application can access Internet -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Permission so that application can write on device storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

在清单文件中


请帮助我。

嗨,我终于成功下载了.cer文件

适用于我的代码如下:

String sourceURL = url;
        String directoryPath = directoryPath;
        DefaultHttpClient client = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(sourceURL);
        try {

            /**
             * getting Session Id from URL which is in Webview
             */
            String sessionId = CookieManager.getInstance().getCookie(
                    sourceURL.toString());
            if (sessionId != null)
                httpPost.addHeader("Cookie", sessionId);
            HttpResponse execute = client.execute(httpPost);
            String certResponseBody = EntityUtils.toString(execute
                    .getEntity());
我在certResponseBody中以字符串形式获取了.cer文件,并将其保存为设备存储中的.cer文件

干杯