17 Kasım 2016 Perşembe

NotificationManager

Giriş
Şu satırı dahil ederiz.
import android.app.NotificationManager;
constructor
Şöyle yaparız.
NotificationManager notificationManager = (NotificationManager)
 getSystemService(Context.NOTIFICATION_SERVICE);
notify metodu - int id
Şöyle yaparız. Her notification'ının bir numarası vardır. Aşağıdaki örnekte 0 verilmiş.
NotificationManager notificationManager = ...
Notification notification = new Notification(...);
..
notificationManager.notify(0, notification);
notify metodu String tag + int id
İmzası şöyle
NotificationManager.notify(String tag, int id, Notification notification)
NotificationCompat.Builder Sınıfı
Şöyle yaparız.
//First time    
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
  .setContentText(context.getString(R.string.notif_text))
  .setContentTitle(title)
  .setSmallIcon(R.drawable.ic_action_alarm_2)
  .setAutoCancel(false)
  .setOngoing(running)
  .setOnlyAlertOnce(true)
  .setContentIntent(
    PendingIntent.getActivity(context, 10,new Intent(context, YourActivity.class)
                  .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
                   0)
  )

notificationManager.notify(id, builder.build());
Eğer builder değil de kendimiz yaratmak istersek şöyle yaparız.
Notification notification = new Notification(R.drawable.noti, notificationTitle,System.currentTimeMillis());

Intent notificationIntent = new Intent(this, SmsActivity.class);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent intent = PendingIntent.getActivity(this, 0,
                notificationIntent, 0);

notification.setLatestEventInfo(this, notificationTitle,notificationMessage, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;


Hiç yorum yok:

Yorum Gönder