nchv
nchv

Reputation: 61

How to get alarm clock start ringing listener in Android?

I have a lock screen application in Android work well and now I want to improve it a bit. When the alarm of the device start ringing my lock screen application must be finish. Please tell me how can I catch the alarm start ringing listener? Thanks in advance.

Upvotes: 1

Views: 1459

Answers (1)

Chaya Sandamali
Chaya Sandamali

Reputation: 667

You can set the BroadcastReceiver to listen to the alarm event. Upon receiving the relevant action you can stop you lock screen application.

Sample code will look like this,

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() 
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
          String action = intent.getAction();
          if (action.equals("com.android.deskclock.ALARM_ALERT") || 
              action.equals("com.android.deskclock.ALARM_SNOOZE") || 
              action.equals("com.android.deskclock.ALARM_DISMISS") || 
              action.equals("com.android.deskclock.ALARM_DONE")) 
          {
              // Stop the screen lock application here...
          }
    }
}; 

Upvotes: 3

Related Questions