Уведомление не появляется (Канал уведомлений) - PullRequest
1 голос
/ 20 сентября 2019

Я хочу установить напоминание из моего приложения.После установки времени я хочу получать напоминание о наступлении установленного времени.Я установил уведомление и пытаюсь настроить каналы уведомлений, но не получаю никаких уведомлений.

Это мой код:

protected void onHandleIntent(Intent intent) {
    createNotificationChannel();
    mTodoText = intent.getStringExtra(TODOTEXT);
    mTodoUUID = (UUID) intent.getSerializableExtra(TODOUUID);
    Intent i = new Intent(this, ReminderActivity.class);
    i.putExtra(TodoNotificationService.TODOUUID, mTodoUUID);
    Intent deleteIntent = new Intent(this, DeleteNotificationService.class);
    deleteIntent.putExtra(TODOUUID, mTodoUUID);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.default_notification_channel_id)).setContentTitle("Reminder").setContentText(mTodoText).setDeleteIntent(PendingIntent.getService(this, mTodoUUID.hashCode(), deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)).setContentIntent(PendingIntent.getActivity(this, mTodoUUID.hashCode(), i, PendingIntent.FLAG_UPDATE_CURRENT)).setPriority(NotificationCompat.PRIORITY_DEFAULT);
    int mNotificationId = (int) System.currentTimeMillis();
    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.notify(mNotificationId, builder.build());
}

private void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = "Reminders Notifications";
        String desc = "Stores reminders";
        int importance = NotificationManager.IMPORTANCE_DEFAULT;

        NotificationChannel notificationChannel = new NotificationChannel(getString(R.string.default_notification_channel_id), name, importance);
        notificationChannel.setDescription(desc);

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);
    }
}
...