Уведомление не показывается - PullRequest
0 голосов
/ 01 апреля 2019

Я не могу сделать это простое уведомление, я продолжал искать учебники, и все они предоставляют один и тот же код.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("hgfyjdgh", "Mychannel", NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }
}

public void click(View v) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "id");
    builder.setSmallIcon(R.drawable.img)
            .setContentTitle("Uber Driver")
            .setContentText("أنت الان متصل")
            .setPriority(NotificationCompat.PRIORITY_HIGH);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(23, builder.build());
    Toast.makeText(this, "done", Toast.LENGTH_LONG).show();

}

1 Ответ

1 голос
/ 01 апреля 2019

Вам необходимо иметь один и тот же канал при создании NotificationChannel и при уведомлении

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

String NOTIFICATION_CHANNEL_ID = "com.appname.example";

Зарегистрировать его

NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "MyChannelName", NotificationManager.IMPORTANCE_DEFAULT);

Сообщить об этом

notificationManager.notify(NOTIFICATION_CHANNEL_ID, builder.build());
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...