progquester
progquester

Reputation: 1776

Occasional crash: SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

There is a very, very low probability that my program will have the following crash:

java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

And once it occurs, it stays crashed unless the phone is restarted.

I need to note that:

  1. permissions android.permission.FOREGROUND_SERVICE and android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION have been added to the Manifest file.

  2. the foreground type has been declared for the service android:foregroundServiceType="mediaProjection"

  3. created Notification Channel and Notification, and called startForeground() when the service was created, and there are logs showing the successful call.

However, there is a 0.001% chance that the exception will be thrown.

And, the phone with the problem will keep having the problem, even if the program crashes and then restarts. And the problem occurs on Android 10, 11, 12, for Android 13, 14, 15 is not found yet.

The command adb shell dumpsys activity and other dump methods are also unable to dump the foreground service type information of a service. How can I investigate this strange issue?

Upvotes: 1

Views: 53

Answers (0)

Related Questions