Cái em dùng là cái này ạ. Tại em thấy khai báo phải ghi vậy android:foregroundServiceType="mediaProjection">
nên chắc gọi là vậy @@. Để bắt đầu service em phải gọi startActivityForResult
trong Mainactivity
startActivityForResult(
mProjectionManager.createScreenCaptureIntent(),
REQUEST_CODE)
Nếu người dùng chập nhận yêu cầu resulcode=result_ok=-1 trả về trong:
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
if (requestCode == REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
val intentx:Intent =ScreenCaptureService.getStartIntent(
this,
resultCode,
data)
startForegroundService(intentx)
Loại này có thể bắt đầu tự động sau khi điện thoại reset được không ạ. Kể từ android 10 người dùng phải cấp quyền thủ công bằng tay(không có ô chọn “không hỏi lại”)mỗi lần gọi startActivityForResult
với mediaprojection. startActivityForResult
hình như cũng không dùng được trong BroadcastReceiver
.