Уведомление службы Foreground ничего не делает, когда телефон заблокирован - PullRequest
0 голосов
/ 08 октября 2018

У меня запущена служба переднего плана с уведомлением, отображаемым на экране даже в заблокированном состоянии.Если я нажимаю на уведомление, когда оно разблокировано, оно успешно открывает мои действия.

Если я нажимаю на уведомление, когда телефон заблокирован, ничего не происходит, пока я не разблокирую телефон.Независимо от того, что я пытаюсь сделать с ожидающим намерением: запустить службу, отправить широковещательную рассылку или начать действие, это происходит только тогда, когда я разблокирую телефон.Он не достигает метода onCreate чего-либо.

Как мне сделать так, чтобы служба переднего плана по-прежнему обрабатывала ожидающие намерения при блокировке?

NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("mychannel",
                "mychannel name",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription("channel desc");
        channel.enableLights(true);
        channel.setLightColor(Color.RED);
        channel.enableVibration(true);
        channel.setShowBadge(false);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        channel.setVibrationPattern(null);
        if (mNotificationManager != null) {
            mNotificationManager.createNotificationChannel(channel);
        }
    }

    // Create notification builder.
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "mychannel")
            .setSmallIcon(R.drawable.ic_action_notification)
            .setColor(getResources().getColor(R.color.colorPrimary))
            .setContentTitle("note title")
            .setContentText("note text)
            .setWhen(0)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setTicker(null)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setLights(Color.RED, 3000, 3000)
            .setVibrate(null)
            .setAutoCancel(false);




    Intent intent = new Intent(this, myclass.class);
    PendingIntent pi = PendingIntent.getActivity(this, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);


    mBuilder.setContentIntent(pi);


    Notification notification = mBuilder.build();

    // Start foreground service.
    startForeground(2, notification);
...