Search This Blog

Tuesday, September 27, 2016

Push - Push cơ bản

private static void generateNotification(Context context, String message) {

    int icon = R.mipmap.ic_launcher;
    long when = System.currentTimeMillis();

    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder b = new NotificationCompat.Builder(context);

    b.setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setWhen(System.currentTimeMillis())
            // icon            
            .setSmallIcon(icon)
            .setTicker("Hearty365")
            // tua de            
            .setContentTitle("Default notification")
            // noi dung            
            .setContentText(message)
            .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
            .setContentIntent(contentIntent)
            .setContentInfo("Info");

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, b.build());

}

No comments:

Post a Comment