如何使用扬声器检测闹钟或其他应用程序? [英] How to detect alarm ringing or other apps using speaker?

查看:29
本文介绍了如何使用扬声器检测闹钟或其他应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款音乐应用.我想检测其他使用扬声器或闹钟播放/暂停音乐的应用.

I am developing a music app. I want to detect that other apps using speaker or alarm ringing for play/pause music.

对于电话,我使用PhoneStateListener.我尝试使用 OnAudioFocusChangeListener 来检测其他音频.但没有奏效.

For phone call i use PhoneStateListener. I tryed OnAudioFocusChangeListener for to detect other audios. But didn't work.

我想知道如何解决这个问题.

I wondering how to solve this problem.

推荐答案

我解决了默认报警应用的问题:

I solved my problem for default alarm application:

public static final String ALARM_ALERT_ACTION = "com.android.deskclock.ALARM_ALERT";
public static final String ALARM_SNOOZE_ACTION = "com.android.deskclock.ALARM_SNOOZE";
public static final String ALARM_DISMISS_ACTION = "com.android.deskclock.ALARM_DISMISS";
public static final String ALARM_DONE_ACTION = "com.android.deskclock.ALARM_DONE";

private BroadcastReceiver mReceiver = new BroadcastReceiver() 
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
          String action = intent.getAction();
          if (action.equals(ALARM_ALERT_ACTION) || action.equals(ALARM_DISMISS_ACTION) || action.equals(ALARM_SNOOZE_ACTION) || action.equals(ALARM_DONE_ACTION)) 
          {
              // for play/pause mediaplayer
              playPause();
          }
    }
};


@Override
public void onCreate(Bundle savedInstanceState) 
{
    IntentFilter filter = new IntentFilter(ALARM_ALERT_ACTION);
    filter.addAction(ALARM_DISMISS_ACTION);
    filter.addAction(ALARM_SNOOZE_ACTION);
    filter.addAction(ALARM_DONE_ACTION);
    registerReceiver(mReceiver, filter);
}

这篇关于如何使用扬声器检测闹钟或其他应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆