Android通知图标未更改

时间:2014-02-25 08:14:54

标签: android notifications

我试图多次更改Notification类中的图标,不幸的是它设置了清单上设置的应用程序图标,而不是我指定的那个。以前有人经历过这个吗?以这种方式,图标在状态栏中缩放到更大(xhdpa)的大小。

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

3 个答案:

答案 0 :(得分:1)

使用NotificationCompat.Builder,为此您需要将support-v4-library导入到项目中。

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();

有关更多信息,请转到我的回答:Notifications Builder in android 2.3

答案 1 :(得分:0)

希望它适合你:)

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());

将支持库v4添加到项目中并导入

import android.support.v4.app.NotificationCompat;

答案 2 :(得分:0)

尝试这可能有用

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);