Rye
Rye

Reputation: 2311

Android Notification Icon Not Changing

I have tried to change the icon on my Notification class several times, unfortunately it is setting the app icon that was set on the manifest, not the one I've assigned. Has anybody experienced this before? In this manner the icon scales to a larger (xhdpa) size in the status bar.

Notification n = new Notification(icon, tickerText, when);

Upvotes: 0

Views: 1626

Answers (3)

M D
M D

Reputation: 47817

Used NotificationCompat.Builder and for this you need to import support-v4-library into you project.

int notifyID = 1;
int icon = R.drawable.logo;
int icon_small = R.drawable.logo;
String title = context.getString(R.string.app_name);

NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo);

Intent notificationIntent = new Intent(context, Login.class);

 Notification noti = new NotificationCompat.Builder(context)
                    .setSmallIcon(icon_small)
                    .setTicker("ticker")
                    .setLargeIcon(largeIcon)
                    .setWhen(System.currentTimeMillis())
                    .setContentTitle(title)
                    .setContentText("message")
                    .setContentIntent(contentIntent)
                    //At most three action buttons can be added
                    .setAutoCancel(true).build();

And for more information go to my answer:Notifications Builder in android 2.3

Upvotes: 1

Kartheek Sarabu
Kartheek Sarabu

Reputation: 3926

Try this may be usefull

NotificationCompat.Builder nBuilder;

    nBuilder = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Heading")
                    .setLights(Color.BLUE, 500, 500).setContentText(message)
                    .setAutoCancel(true).setTicker("Notification")
                    .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
                    .setSound(alarmSound);

Upvotes: 0

Harshal Benake
Harshal Benake

Reputation: 2401

Hope it works for you :)

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(getApplicationContext(), MYDEMOACTIVITY.class);

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MYDEMOACTIVITY.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
        );
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());

And add support library v4 into your project and also import

import android.support.v4.app.NotificationCompat;

Upvotes: 0

Related Questions