在安卓系统中如何让通知图标闪烁?

5
我搜索了很多东西,比如:如何在Google地图上显示闪烁的图标

但是根据这个链接,我没有找到如何使通知图标闪烁的方法。

我想让这个图标闪烁。

 int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, "Hi M rohit", when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, Home.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, "Rohit", intent);
//notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(NOTIFICATION, notification);
2个回答

7
我找到了解决方案:我创建了一个动画文件并设置了该文件,谢谢,我找到了解决方案。
在此处设置文件名:-
   int icon = R.drawable.animationfile;
long when = System.currentTimeMillis();
notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, "Your location is tracing", when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, Home.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, "Rohit", intent);
//notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(NOTIFICATION, notification);

i created this file

animationfile.xml :

  <animation-list
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
<item android:drawable="@drawable/icaon" android:duration="10000" />
<item android:drawable="@drawable/icon" android:duration="10000" />
</animation-list>

没有设置滚动文本,它就无法工作!虽然它被显示出来了,但并没有动画效果。看起来只有在调用setTicker(...)时才会有动画效果。 - Aron Lorincz
@ÁronNemmondommegavezetéknevem 我猜这与那个 bug https://code.google.com/p/android/issues/detail?id=15657 有关。 - user276648

3
要显示上传或下载通知,就像在Android中默认的那样(一个向上或向下移动的箭头,就像这个like,直到上传或下载完成),只需使用以下内容。
将您的通知构建器设置为:
mBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
mBuilder.setTicker(mContext.getString(R.string.notification_ticker)); //Pass an empty string if you dont want any text to appear on the status bar
//Call notify() method of notification manager to see the effect

如果您希望上传或下载完成后停止动画图标,请使用以下方法:

 mBuilder.setSmallIcon(R.drawable.ic_download); //ic_download is similar looking icon in your drawable folder
 mNotifyManager.notify(0, mBuilder.build());

希望这能帮到你。 :)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接