Показано Android Q Bubble от AccessibilyService - PullRequest
0 голосов
/ 29 января 2020

Итак, у меня есть служба доступности в android, и я хотел бы вызвать новый пузырь Android X. Возникли некоторые проблемы, поскольку уведомление просто отображается как простое уведомление. Тем не менее, учитывая документацию, она должна отображаться, если The notification uses MessagingStyle, and has a Person added. Что я думаю, я делаю Вот что у меня есть:

public class Watcher extends AccessibilityService {

    static final String TAG = "WatcherService";
    private View main;
    private ImageView imageView;
    Button createBubble;

    Notification.Builder builder;
    NotificationManager notificationManager;
    NotificationChannel channel;
   public void createBubble() {
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        CharSequence name = "My new channel";
        String description = "Description";
        int importance = NotificationManager.IMPORTANCE_HIGH;

        channel = new NotificationChannel("10101001", name, importance);
        channel.setDescription(description);
        channel.setAllowBubbles(true);

        Intent target = new Intent(Watcher.this, BubbleActivity.class);

        PendingIntent bubbleIntent =
                PendingIntent.getActivity(Watcher.this, 0, target, PendingIntent.FLAG_UPDATE_CURRENT /* flags */);

        Notification.BubbleMetadata bubbleData =
                new Notification.BubbleMetadata.Builder()
                        .setDesiredHeight(600)
                        .setIcon(Icon.createWithResource(Watcher.this, R.drawable.ic_close))
                        .setIntent(bubbleIntent)
                        .build();

        Person chatBot = new Person.Builder()
                .setBot(true)
                .setName("BubbleBot")
                .setImportant(true)
                .build();

        CharSequence cs = "string";


        Notification.MessagingStyle style = new Notification.MessagingStyle(chatBot)
                .setGroupConversation(false);

        builder = new Notification.Builder(Watcher.this, channel.getId())
                .setSmallIcon(R.drawable.ic_close)
                .setBubbleMetadata(bubbleData)
                .setCategory(NotificationCompat.CATEGORY_CALL)
                .setStyle(style)
                .addPerson(chatBot);

        notificationManager.createNotificationChannel(channel);
        notificationManager.notify(1, builder.build());
    }

Любая помощь будет отличной, спасибо!

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

...