How I can change the icon & largeIcon in my notification? I'm trying this code:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification notification = builder
.setSmallIcon(android.R.drawable.stat_notify_more)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("text").build();
notificationManager.notify(666, notification);
This works great, notification was displayed. But the notification are stil the same like application icon
, not the "stat_notifi_more
" from android drawable
, why?
And also the STATUS BAR ICON
(notification small icon at the top- left side next to battery, wifi and others) does not shows too!
Can someone help me with this?
Edit: I have lollipop 5.1.1 and android 24 (sdk)
EDIT2:
The notification icon (OK) (96x96px):
Status bar icon (24x24px) (NOT OK, default application icon):
real status bar icon:
Notification source:
// Using RemoteViews to bind custom layouts into Notification
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.notification_layout);
// Set Notification Title
String strtitle = "title";
// Set Notification Text
String strtext = "text";
// Open NotificationView Class on Notification Click
Intent intent = new Intent(this, MainActivity.class);
// Send data to NotificationView Class
intent.putExtra("title", strtitle);
intent.putExtra("text", strtext);
// Open NotificationView.java Activity
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Locate and set the Image into customnotificationtext.xml ImageViews
remoteViews.setImageViewResource(R.id.imagenotileft, R.drawable.stacionar_xhdpi_green);
// Locate and set the Text into customnotificationtext.xml TextViews
remoteViews.setTextViewText(R.id.title, "title");
remoteViews.setTextViewText(R.id.text, "content");
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.wall_black)
.setTicker("t")
.setContentIntent(pIntent)
.setContent(remoteViews);
// Create Notification Manager
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Build Notification with Notification Manager
notificationmanager.notify(0, builder.build());
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imagenotileft"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imagenotileft" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/imagenotileft" />
</RelativeLayout>