Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited body
Source Link
Henry
  • 17.9k
  • 7
  • 68
  • 99

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. ThemThen simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

So for example you would need to:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

     <!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder --> <animation-list android:id="selected" android:oneshot="false"> <item android:drawable="@drawable/wheel0" android:duration="50" /> <item android:drawable="@drawable/wheel1" android:duration="50" /> <item android:drawable="@drawable/wheel2" android:duration="50" /> <item android:drawable="@drawable/wheel3" android:duration="50" /> <item android:drawable="@drawable/wheel4" android:duration="50" /> <item android:drawable="@drawable/wheel5" android:duration="50" /> </animation-list> 
  2. Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/ folder as well.

  3. Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

     Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification); 

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. Them simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

So for example you would need to:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

     <!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder --> <animation-list android:id="selected" android:oneshot="false"> <item android:drawable="@drawable/wheel0" android:duration="50" /> <item android:drawable="@drawable/wheel1" android:duration="50" /> <item android:drawable="@drawable/wheel2" android:duration="50" /> <item android:drawable="@drawable/wheel3" android:duration="50" /> <item android:drawable="@drawable/wheel4" android:duration="50" /> <item android:drawable="@drawable/wheel5" android:duration="50" /> </animation-list> 
  2. Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/ folder as well.

  3. Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

     Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification); 

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. Then simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

So for example you would need to:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

     <!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder --> <animation-list android:id="selected" android:oneshot="false"> <item android:drawable="@drawable/wheel0" android:duration="50" /> <item android:drawable="@drawable/wheel1" android:duration="50" /> <item android:drawable="@drawable/wheel2" android:duration="50" /> <item android:drawable="@drawable/wheel3" android:duration="50" /> <item android:drawable="@drawable/wheel4" android:duration="50" /> <item android:drawable="@drawable/wheel5" android:duration="50" /> </animation-list> 
  2. Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/ folder as well.

  3. Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

     Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification); 
deleted 16 characters in body
Source Link
Peter O.
  • 33.1k
  • 14
  • 86
  • 97

I know this is an old question - but I'm hoping to help anyone else who stumbles on this question...

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. Them simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

So for example you would need to:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

     
     <!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder --> <animation-list android:id="selected" android:oneshot="false"> <item android:drawable="@drawable/wheel0" android:duration="50" /> <item android:drawable="@drawable/wheel1" android:duration="50" /> <item android:drawable="@drawable/wheel2" android:duration="50" /> <item android:drawable="@drawable/wheel3" android:duration="50" /> <item android:drawable="@drawable/wheel4" android:duration="50" /> <item android:drawable="@drawable/wheel5" android:duration="50" /> </animation-list> 
  2. Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/res/drawable/ folder as well.

  3. Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

    Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis());

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification);

     Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification); 

I know this is an old question - but I'm hoping to help anyone else who stumbles on this question...

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. Them simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

So for example you would need to:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

     
  2. Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/ folder as well.

  3. Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

    Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis());

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification);

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. Them simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

So for example you would need to:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

     <!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder --> <animation-list android:id="selected" android:oneshot="false"> <item android:drawable="@drawable/wheel0" android:duration="50" /> <item android:drawable="@drawable/wheel1" android:duration="50" /> <item android:drawable="@drawable/wheel2" android:duration="50" /> <item android:drawable="@drawable/wheel3" android:duration="50" /> <item android:drawable="@drawable/wheel4" android:duration="50" /> <item android:drawable="@drawable/wheel5" android:duration="50" /> </animation-list> 
  2. Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/ folder as well.

  3. Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

     Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification); 
Source Link

I know this is an old question - but I'm hoping to help anyone else who stumbles on this question...

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. Them simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

So for example you would need to:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

  2. Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/ folder as well.

  3. Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

    Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis());

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification);