Android 5.0 (Lollipop) Service Intent must be explicit

后端 未结 1 1579
深忆病人
深忆病人 2021-01-27 11:31

I am working on a widget and code is working fine on pre Lollipop devices but when I run my code on Lollipop, it gives me error Service Intent must be explicit: Intent { a

相关标签:
1条回答
  • 2021-01-27 12:24

    Instantiating an Intent with only an action creates what is referred to as an implicit Intent, since any component registered to handle that action will be started in order to do so. As of Lollipop, Services can no longer be started with implicit Intents due to security concerns. You merely need to be specific about the class the Intent is meant for; i.e., use an explicit Intent.

    context.startService(new Intent(context, UpdateService.class));
    

    You should also remove the <intent-filter> element from the Service in the manifest, as that is what allows your Service to be started with an implicit Intent, which is no longer allowed.

    0 讨论(0)
提交回复
热议问题