Создание уведомления - PullRequest
       5

Создание уведомления

0 голосов
/ 02 февраля 2020

Попытка отправить сообщение в область уведомлений:

public void sendNotification (View view) {


    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(android.R.drawable.ic_dialog_alert);
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.journaldev.com/"));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    builder.setContentIntent(pendingIntent);
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    builder.setContentTitle("Notifications Title");
    builder.setContentText("Your notification content here.");
    builder.setSubText("Tap to view the website.");

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // Will display the notification in the notification bar
    notificationManager.notify(1, builder.build());
}


public void cancelNotification(View view){

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(ns);
    nMgr.cancel(1);


}

Но я ничего не получил, когда нажал кнопку с вызовом на sendNotification.

Что я делаю не так?

...