有没有示例应用程序演示android的Telephony API的功能?我对获得呼叫通知/呼叫者号码等很感兴趣(我知道用PhoneStateListener是可行的)。另外,第三方应用程序是否可以更改来电窗口/去电窗口(基本上是给用户一个额外的按钮来搜索REST服务中的来电号码)?
任何有用的链接或示例应用程序都会非常有帮助。有什么建议吗?
发布于 2010-11-29 04:22:49
PhoneStateListener告诉你的应用程序有关电话活动的信息。下面是我的一个应用程序中的一些示例代码,它可以在手机处于活动状态时暂停音乐:
/**
* Helper class to pause music while a phone call is in progress.
*
* The Android emulator can simulate an outgoing call by clicking
* the phone button and dialing normally. Simulate an incoming call
* by starting the emulator, "telnet localhost 5554" then enter
* "gsm call 5551234" into the telnet session.
*/
private class MusicServicePhoneStateListener extends PhoneStateListener {
private boolean mResumeAfterCall = false;
@Override
public void onCallStateChanged(int state, String incoming_number) {
switch (state) {
case TelephonyManager.CALL_STATE_OFFHOOK:
case TelephonyManager.CALL_STATE_RINGING:
Log.i(tag, "phone active, suspending music service");
mResumeAfterCall = mMediaPlayer.isPlaying();
mMediaPlayer.pause();
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.i(tag, "phone inactive, resuming music service");
if (mResumeAfterCall) {
mMediaPlayer.start();
}
break;
default:
break;
}
}
}通过以下方式在onCreate中创建并启动监听程序:
mPhoneListener = new MusicServicePhoneStateListener();
((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);使用以下命令停止onDestroy中的监听程序:
((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).listen(mPhoneListener, 0);至于修改来电对话,best suggestion I've found将使用一个短的延迟,然后是一个自定义的toast消息(延迟,以便您的toast显示在来电对话框的“上方”)。
https://stackoverflow.com/questions/4298254
复制相似问题