Snippets

gourav nema Simple Notification in Android

Created by Gourav Nema last modified
public class NotificationActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification);

        //get a notification manager from the context
        NotificationManager notificationManager = (NotificationManager)
                getSystemService(NOTIFICATION_SERVICE);
        //get notification object from the builder using it's context
        Notification n = new Notification.Builder(this)
                .setContentTitle("App Started")
                .setContentText("This is the first app")
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
                .build();
        //push notification
        notificationManager.notify(0,n);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.