Я разрабатываю приложение, которое записывает экран с использованием API проекции среды и передаю данные в представление на поверхности наложения, однако компоненты вида поверхности и наложения видны, но прогнозируемый дисплей не был виден в представлении поверхности. (Вот мой репозиторий, чтобы попробовать его: https://github.com/xinzhao2627/eapp3/tr ... plicitapp3)образно />@RequiresApi(api = Build.VERSION_CODES.O)
private void setupOverlay() {
LayoutInflater lf = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
// this is the overlay view
View view = lf.inflate(R.layout.activity_overlay, null);
screenMirror = view.findViewById(R.id.screenMirror);
mSurface = screenMirror.getHolder().getSurface();
screenMirror.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
mSurface = holder.getSurface();
if (mMediaProjection != null) startScreenCapture();
}
@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
@Override public void surfaceDestroyed(SurfaceHolder holder) {}
});
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
900,
500,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.OPAQUE
);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 100;
params.y = 100;
// init the imageview
windowManager.addView(view, params);
}
< /code>
Что делает этот выше код, это отображение поверхностного представления сверху экрана. Затем я сделал следующую функцию startScreenCapture (): < /p>
public void startScreenCapture() {
MediaProjection.Callback callback = new MediaProjection.Callback() {
@Override
public void onStop() {
super.onStop();
stopScreenCapture();
}
};
mMediaProjection.registerCallback(callback, null);
mVirtualDisplay = mMediaProjection.createVirtualDisplay(
"ScreenCapture",
900,
500,
getResources().getDisplayMetrics().densityDpi,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mSurface,
null,
null
);
}
< /code>
Таким образом, код должен проецировать отображение в мою Msurface. Однако он просто показывает пустой экран, и нет никаких журналов ошибок, поэтому я не могу точно определить вероятной причины. От Surfaceview до TextureView Однако нет визуальных изменений.
Настройка манифеста Android и добавление пользовательских разрешений:
andride.permission.foreground_service ,образное /> android.permission.system_alert_windowобразное время.@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
NotificationHelper.createNotificationChannel(getApplicationContext());
notification = NotificationHelper.createNotification(getApplicationContext());
startForeground(SERVICE_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION);
}
int rc = intent.getIntExtra("resultCode", -1);
Intent d = intent.getParcelableExtra("data");
if (rc != -1 && d != null) {
mMediaProjection = mediaProjectionManager.getMediaProjection(rc, d);
if (mMediaProjection != null && mSurface != null) {
startScreenCapture();
}
}
return START_STICKY;
}
из natificationHelper.class
private static final String CHANNEL_ID = "screen_recording_channel";
public static Notification createNotification(Context context) {
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
0,
intent,
PendingIntent.FLAG_IMMUTABLE
);
return new NotificationCompat.Builder(context, CHANNEL_ID)
.setContentTitle("Screen recording")
.setContentText("Recording in progress...")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentIntent(pendingIntent)
.build();
}
public static void createNotificationChannel(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel = new NotificationChannel(
CHANNEL_ID,
"Screen Recording Channel",
NotificationManager.IMPORTANCE_DEFAULT
);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(serviceChannel);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... e-view-ove
Проектируемый экран с использованием API проекции медиа -проекции не отображается в наложении вида поверхности в Android ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение