【发布时间】:2018-01-23 08:13:04
【问题描述】:
我可以从 WebView 下载文件,但通知面板中没有显示进度条。但是如果我转到 Ext 存储的下载目录,我可以看到该文件。
如何使下载进度条可见。任何帮助将不胜感激。
这是库中启动下载的代码
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
});
我的清单文件是
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/icon"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.TransNav">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".UpdateDialog"
android:theme="@style/Theme.AppCompat.Dialog" />
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name=".UpdateService"
android:enabled="true"
android:exported="true" />
</application>
任何帮助将不胜感激。为了记录,下载链接是从谷歌驱动器生成的
我的主要活动文件以:
开头public class MainActivity extends AppCompatActivity {
boolean doubleBackToExitPressed = false;
private TextView textView;
private BottomBar bottomBar;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
【问题讨论】:
-
您正在检查哪个操作系统?在棉花糖下面还是在它之后?
-
我认为您的文件已下载但您无法查看该文件是这种情况吗?
-
@FarazAhmed 是的,我注意到,文件确实在下载目录中。那我该怎么解决。因为我也有 bluestacks 模拟器是 4.4.2 版本,我的设备也是相同的版本。但是当我在bluestacks中运行时可以看到下载进度条,如果我通过我的设备运行则不存在。
-
@FarazAhmed 我已经编辑了我的问题。感谢您为我指明正确的方向。
标签: java android eclipse android-studio webview