Skip to content

Instantly share code, notes, and snippets.

@jcguarinpenaranda
Created September 26, 2015 18:11
Show Gist options
  • Save jcguarinpenaranda/6807c174ab4db38350eb to your computer and use it in GitHub Desktop.
Save jcguarinpenaranda/6807c174ab4db38350eb to your computer and use it in GitHub Desktop.
Notify in android statusbar method
private void notifyStatusBar(String title, String text){
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
Notification n = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(text)
.setTicker(text)
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.setAutoCancel(true)
.build();
notificationManager.notify(0, n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment