是在使用系统录屏服务时在29版本以上需要开启一个前台通知
    在开启录屏之前,在service里调用如下代码,总之在getMediaProjection之前调用就行

    1. public void createNotification() {
    2. if (Build.VERSION.SDK_INT >= 26) {
    3. Intent notificationIntent = new Intent(this, FloatWindowsService.class);
    4. PendingIntent pendingIntent;
    5. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
    6. pendingIntent = PendingIntent.getActivity(this, 123, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
    7. } else {
    8. pendingIntent = PendingIntent.getActivity(this, 123, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
    9. }
    10. Notification.Builder notificationBuilder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
    11. .setLargeIcon(ImageUtils.getBitmap(R.mipmap.ic_launcher))
    12. .setSmallIcon(R.mipmap.ic_launcher)
    13. .setContentTitle("化无助手")
    14. .setContentText("持续运行以识别屏幕内容")
    15. .setTicker("test")
    16. .setContentIntent(pendingIntent);
    17. Notification notification = notificationBuilder.build();
    18. NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
    19. channel.setDescription(NOTIFICATION_CHANNEL_DESC);
    20. NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    21. notificationManager.createNotificationChannel(channel);
    22. this.startForeground(NOTIFICATION_ID, notification);
    23. }
    24. }

    image.png
    image.png