Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display a simple notification in android? [closed]

Tags:

java

android

How can I display a simple notification in notification bar in Android? Please help me with the easiest solution.

like image 746
Andromise Avatar asked May 16 '13 10:05

Andromise


1 Answers

I assume you are asking about notification in notificationbar.If its so,Try this code,

private void showNotification(String eventtext, Context ctx) {



    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.noti_icon,
            text, System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this
    // notification
    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
            new Intent(ctx, MainActivity.class), 0);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(ctx, "Title", eventtext,
            contentIntent);

    // Send the notification.
    mNotificationManager.notify("Title", 0, notification);
}
like image 98
Basim Sherif Avatar answered Sep 19 '22 15:09

Basim Sherif