如何检测报警铃声或其他应用程序使用音箱?或其他、应用程序、音箱、铃声

由网友(帅的被人砍)分享简介:我开发一个音乐应用程序。我想用喇叭或报警铃声的播放/暂停音乐检测到其他应用程序。I am developing a music app. I want to detect that other apps using speaker or alarm ringing for play/pause music.有关的电...

我开发一个音乐应用程序。我想用喇叭或报警铃声的播放/暂停音乐检测到其他应用程序。

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

有关的电话我使用PhoneStateListener。我trye​​d 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);
}
阅读全文

相关推荐

最新文章