【发布时间】:2012-06-22 20:36:55
【问题描述】:
我有一个从应用程序类播放音频的 android 应用程序。我的应用程序类中有一个 PhoneStateListener,它在有电话时暂停音频。
我想在通话结束时开始一项特定的活动,但我做不到。这是我的代码:
public void getPhoneState(){
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
if(audio.isPlaying())
audioPlayer.pause();
}
else if(state == TelephonyManager.CALL_STATE_IDLE) {
audio.start();
Intent missintent= new Intent(context,AudioActivity.class);
missintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(missintent);
}
else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
if(audio.isPlaying())
audioPlayer.pause();
}
super.onCallStateChanged(state, incomingNumber);
}
};
if(mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
public boolean handleAudio(String source, int id) {
phoneState();
//Code for Playing Audio
.....
.....
}
如果有人能告诉我如何以正确的方式开始活动,我将不胜感激。
谢谢!
【问题讨论】:
-
我不确定在这个问题上的正确方法,因为我从来没有这样做过,也不知道你是否应该从应用程序类开始一个活动,因为你总是设置清单上的入口类,但考虑到您可以做到...您是否将活动添加到清单中?
-
我的活动已添加到清单中。不能从应用程序类启动活动吗?
-
我没说不是。我说我不知道,因为我从来没有这样做过,因为清单上已经有了 start 类,由意图定义:
-
@RaghavShankar 我有一个非常相似的问题,你找到任何解决方案了吗?
-
“但我做不到。” : 你需要告诉我们发生了什么。描述 + 日志
标签: android android-intent event-handling listener android-mediaplayer