Daniel Zhao
Daniel Zhao

Reputation: 76

How to use a Bitmap as a Notification Icon

I want to draw something on a pic , after do that , it is a Bitmap . i want to add this Bitmap to the Notification as its icon. but it the icon must be a int Id . How can i make it? thanks for your answer~~~~ pls hlep me!

Upvotes: 5

Views: 4660

Answers (6)

user3712658
user3712658

Reputation: 1

If you're using Android Studio, you can always convert your original image to an Image Asset and that should generate the right image format that you can readily use, i.e. assign an ID. You can opt to overwrite the default resource name or have a different one.

Upvotes: 0

thecr0w
thecr0w

Reputation: 2197

try using xml draw your image, and put it in icon like n.icon = R.drawable.x;

drawable/x.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/write_normal_battery1" />
    <item android:drawable="@drawable/notif_0" android:left="5.5dip" android:right="13.5dip" />
    <item android:drawable="@drawable/notif_9" android:left="13.5dip" android:right="5.5dip" />
</layer-list>

Upvotes: 0

Abhi
Abhi

Reputation: 9005

From this Post i came to know that Notification icon will take Resources image. So You cant do dynamic in Small icon. But you can do for large icon from Api Level 11.

For that you can use Notificaiton.Builder Refer here

Other way is also there. That is you can change icon that appears when notification in pulled down. For that you have to Use RemoteViews

Refer here

Upvotes: 5

AkashG
AkashG

Reputation: 7888

Try this:

NotificationManager notificationManager=
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon=R.drawable.ic_launcher;
CharSequence text="Notification Text";
long when=System.currentTimeMillis();

Notification notification=new Notification(icon, text, when);
notificationManager.notify(Constants.NOTIFICATION_ID, notification);

I have taken the default image you can keep image file in res->drawable (or drawable-hdpi,ldpi,mdpi) folder.Assign any bitmap to the icon and you will get desired output.

Upvotes: 0

Deepika Lalra
Deepika Lalra

Reputation: 1045

convert you bitmap as a drawable and then you can use it as a notification icon in your dialog.

Upvotes: 0

Jay
Jay

Reputation: 1492

You can put image file in res->drawable (or drawable-hdpi,ldpi,mdpi), for example notify.png and use it

myNotification = new Notification(R.id.notify, "Notification!", System.currentTimeMillis());

or

Try using AnimationDrawable's. You can use them to combine multiple drawables into a single one, and select the one you want to display. I really think, this is the way to go.

More info: AnimationDrawable

Off course, you will have to provide individual drawables for all your Integers you want to display, but this way, you can easily change the appearance of your notifications

Upvotes: 2

Related Questions