简体   繁体   English

下载文件时的通知图标

[英]Notification Icon when downloading file

Does anyone knows how to use notification icon in status bar when downloading a file? 有人知道如何在下载文件时在状态栏中使用通知图标吗? Just like when you are downloading a file in app store. 就像在app store中下载文件一样。 The icon is like in gif. 图标就像在gif中。

只需使用默认的android资源android.R.drawable.stat_sys_download

Here's a fully functioning example that will show the default "system" download notification icon in the status bar. 这是一个功能完备的示例,它将在状态栏中显示默认的“系统”下载通知图标。

private static void showProgressNotification(Context context, int notificationId, String title, String message)
{
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);

    mBuilder.setContentTitle(title)
    .setContentText(message)
    .setSmallIcon(android.R.drawable.stat_sys_download)
    .setTicker("")
    .setProgress(0, 0, true);

    manager.notify(notificationId, mBuilder.build());
}

And when your "download" operation is done, clear the notification: 当您的“下载”操作完成后,请清除通知:

private static void hideProgressNotification(final NotificationManager manager, final Context context, final int id)
{
    manager.cancel(id);
}

Take a look to Android Download Manager. 看看Android下载管理器。 It shows a notification icon indicating that there are files downloading. 它显示一个通知图标,表示有文件下载。 Android Download Manager Android下载管理器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM