New to Android development. I'm wondering if its possible to programmatically draw an icon to put in the notification bar? What if we want the icon to display some dynamic text for something like battery level?
If anyone has a code sample it would be nice. Thanks.
Call the function where we want notification.
public void notification(String name) {
final int id = 2;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.fbc;
CharSequence tickerText = "facebook";
long when = System.currentTimeMillis();
Notification checkin_notification = new Notification(icon, tickerText,
when);
Context context = getApplicationContext();
CharSequence contentTitle = "You are name is"+ name;
CharSequence contentText = "Do You want to Check-in ?? ";
Intent notificationIntent = new Intent(context, LoginTab.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
checkin_notification.setLatestEventInfo(context, contentTitle,
contentText, contentIntent);
checkin_notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(id, checkin_notification);
}
Notification Manager.
Example here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With