MediaProjection service type not recognized in android Q

后端 未结 2 1142
青春惊慌失措
青春惊慌失措 2021-02-14 16:15

With the new privacy changes in effect with Android Q, it is now mandatory for any app using MediaProjection api to specify android:foregroundServiceType attribute

相关标签:
2条回答
  • 2021-02-14 16:25

    Don't you forget to add permission <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> into AndroidManifest.xml ?

    UPDATE

    Make sure you call startForeground() before getMediaProjection()!

    The best solution is to call startForeground() from onCreate() without any conditions, displaying some sort of default messages in notification. Then you can execute your logic and call NotificationManager.notify() with updated notification at any time.

    0 讨论(0)
  • 2021-02-14 16:41

    Changing the following attributes

    android:foregroundServiceType="mediaProjection"
    
    tools:targetApi="q"
    

    in AndroidManifest.xml worked for me.

    < service
    
    android:name="SERVICE_NAME"
    
    android:foregroundServiceType="mediaProjection"
    
    tools:targetApi="q"
    
    android:enabled="true"
    
    android:exported="false" />
    
    0 讨论(0)
提交回复
热议问题