Android中的MediaProjection服务问题

时间:2018-04-23 07:30:22

标签: android android-mediaprojection

当用户在移动设备上安装应用程序时,他/她需要授予MediaProjection系统服务权限才能启动屏幕截图功能。每当用户重新启动移动设备时,用户每次都需要手动授予MediaProjection服务权限。我想这样做,因此用户只需要在移动设备上安装应用程序时只提供一次MediaProjection权限,这样用户每次启动移动设备时都不需要分配权限。

其他问题是MediaProjection Service在一段时间后自动/随机停止。

当我们手动启用权限时,此代码启动MediaProjection系统服务permisison:

MediaProjectionManager projectionManager = (MediaProjectionManager) 
_context.getSystemService(MEDIA_PROJECTION_SERVICE);
intent = projectionManager.createScreenCaptureIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
((Activity)_context).startActivityForResult(intent,REQUEST_SCREENSHOT);

此代码在移动设备重新启动时启动Service类。因此,当服务启动时,它不会自动设置MediaProjection权限。

Intent myIntent = new Intent(context, ScreentshotService.class);
myIntent.setAction(Intent.ACTION_BOOT_COMPLETED);
myIntent.putExtra("code", code);
myIntent.putExtra("data",intent1);
context.startService(myIntent);

我使用上面的代码重新启动后调用 Service.class ,但它没有启动 MediaProjection服务

0 个答案:

没有答案