Creating and Showing an Android System Notification

A Android system notifications are normally used for sending notifications by Android services.

Here how you create simple notification.

public void showNotification(CharSequence message)
{
    final int notifyRef = 1;
    final int notifyIcon = R.drawable.icon;
    final long notifyWhen = System.currentTimeMillis();
    final String notifyService = Context.NOTIFICATION_SERVICE;
    
    NotificationManager notifyManager = (NotificationManager)getSystemService(notifyService);
    Notification notification = new Notification(
       notifyIcon, message, notifyWhen);
    
    Context context = getApplicationContext();
    CharSequence notifyTitle = message;
    CharSequence notifyText = "You saved this message.";
    Intent notifyIntent = new Intent(
       this, MyAndroidSdkAppActivity2.class);
    PendingIntent contentIntent = PendingIntent.getActivity(
       this, 0, notifyIntent, 0);
       notification.setLatestEventInfo(
           context, notifyTitle, notifyText, contentIntent);
       notifyManager.notify(notifyRef, notification);
}

Comments

Popular posts from this blog

Offers on Friday, April 24, 2020

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'