Skip to end of metadata
Go to start of metadata

При сборке приложения, нацеленного на Android 10 (API level 29) и новее, для захвата потока с экрана перед запросом разрешений необходимо запустить сервис типа ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION:

private void startScreenCapture() {
    mMediaProjectionManager = (MediaProjectionManager) getSystemService(
            Context.MEDIA_PROJECTION_SERVICE);
    Intent permissionIntent = mMediaProjectionManager.createScreenCaptureIntent();
    startService(new Intent(StreamingMinActivity.this, TestService.class));
    startActivityForResult(permissionIntent, REQUEST_CODE_CAPTURE_PERM);
}
private void showNotification() {
    Intent notificationIntent = new Intent(this, StreamingMinActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    int iconId = R.mipmap.ic_launcher;
    int uniqueCode = new Random().nextInt(Integer.MAX_VALUE);
    Notification notification = new NotificationCompat.Builder(this)
            .setSmallIcon(iconId)
            .setContentText("Started stream")
            .setContentIntent(pendingIntent).build();
    startForeground(uniqueCode, notification, FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION);
}
  • No labels