5

I searched many things as like : How to show icon blinking on google map

but according to this i don't find how to blink notification icon blink

i want to blink icon on this

 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);
Community
  • 1
  • 1
Rohit
  • 3,401
  • 4
  • 33
  • 60

2 Answers2

7

i found solution :i created animation file and set that file , thanks i found solution

SET FILE name here:-

   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>
Rohit
  • 3,401
  • 4
  • 33
  • 60
  • It didn't work without having a ticker set! It was shown but wasn't animated. It looks like it will only be animated if you also call setTicker(...). – Aron Lorincz Jul 24 '14 at 11:08
  • @ÁronNemmondommegavezetéknevem I guess it's linked to that bug https://code.google.com/p/android/issues/detail?id=15657 – user276648 Jul 30 '15 at 08:38
3

To show the upload or download notification like the default one which we have in android (an up or down arrow moving up or down respectively like this like, till the upload or download is completed), simply use the below.

Set your notification builder to,

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

And when you want the animated icon to stop after the upload or download is completed use below,

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

Hope this helps. :)

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74