How To give notifications on android on specific time?

前端 未结 4 568
傲寒
傲寒 2020-12-02 09:10

I want to give notification to my app on a specific time. Say everyday i have to give notification on 7 AM even if the app is closed.

How can i do this? Any tutorial

4条回答
  •  余生分开走
    2020-12-02 10:09

    A solution from the accepted answer will not work properly on Android 8 Oreo (api level 26) and higher due to background service limits (https://developer.android.com/about/versions/oreo/background.html#services) and will cause an exception like this when the app is in background:

    java.lang.IllegalStateException: Not allowed to start service Intent xxx: app is in background
    

    One of the possible workarounds is using JobIntentService:

    1. extend your Service from JobIntentService instead of IntentService and use onHandleWork method instead of onHandleIntent.

    2. add android:permission="android.permission.BIND_JOB_SERVICE" to your Service in AndroidManifest.xml.

提交回复
热议问题