Search code examples
androidkotlinalarmmanager

AlarmManager in Android works only in an emulator and does not on a physical device


I created an application with AlarmManager and Notification but it works only on an emulator. When I run the app on my physical device the notifications are not shown despite the fact that in app info there is information about the notifications.

EDIT: I've found the solution in this thread


Solution

  • As your Alarm completes 60 secs or whenever you need to trigger the notification, invoke the following function:-

    triggerNotification(){
    Intent intent = new Intent(getContext(),DailyNotificationReceiver.class);
    sendBroadcast(intent);
    }
    //after every min lapsed invoke this function
    

    This is in java, convert it into kotlin. This sendBroadcast function will internally call your onReceive method