13 个解决方案
#1
使用 android.telephony.PhoneStateListener
#2
这方法不行的
#3
这方法不行的,
#4
没问题啊,哪里不行了
#5
我试过,用真机测试,当接通的时候PhoneStateListener没反应
#6
off hook状态,有反应啊,你什么机器,固件和型号
#7
实现不了。我花了很长时间去研究过,网上很多方法都试过,都不行,唯一可以的就是改底层。你看log可以看出,当接通了系统会有反应,但是这个函数是不公开的,要改我觉得要重写phone类
#8
不用改底层,取得TelephonyManager,监听CALL_STATE_RINGING就可以
#9
拨入电话监听:
import android.os.RemoteException;
import android.telephony.PhoneStateListener;
import com.android.internal.telephony.ITelephony;
public class IncomingCallListener extends PhoneStateListener {
private CallStateObserver mCallStateListener = null;
private ITelephony mPhone;
public IncomingCallListener(CallStateObserver callStateListener, ITelephony phone) {
mCallStateListener = callStateListener;
mPhone = phone;
}
public void onCallStateChanged(int state, String incomingNumber) {
MyLog.d("incomingNumber="+incomingNumber);
mCallStateListener.onPhoneRinging(incomingNumber);
try {
mPhone.answerRingingCall();
// mPhone.showCallScreen();
// mPhone.showCallScreenWithDialpad(false);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
拨出电话监听:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class OutgoingCallReceiver extends BroadcastReceiver {
private CallStateObserver mCallStateObserver = null;
public OutgoingCallReceiver(CallStateObserver callStateObserver) {
mCallStateObserver = callStateObserver;
}
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
String phoneNum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
MyLog.d("outgoingNumber=" + phoneNum);
mCallStateObserver.onIpCallAvaliable();
}
}
}
自己写的,我试了可以,你试试吧。
import android.os.RemoteException;
import android.telephony.PhoneStateListener;
import com.android.internal.telephony.ITelephony;
public class IncomingCallListener extends PhoneStateListener {
private CallStateObserver mCallStateListener = null;
private ITelephony mPhone;
public IncomingCallListener(CallStateObserver callStateListener, ITelephony phone) {
mCallStateListener = callStateListener;
mPhone = phone;
}
public void onCallStateChanged(int state, String incomingNumber) {
MyLog.d("incomingNumber="+incomingNumber);
mCallStateListener.onPhoneRinging(incomingNumber);
try {
mPhone.answerRingingCall();
// mPhone.showCallScreen();
// mPhone.showCallScreenWithDialpad(false);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
拨出电话监听:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class OutgoingCallReceiver extends BroadcastReceiver {
private CallStateObserver mCallStateObserver = null;
public OutgoingCallReceiver(CallStateObserver callStateObserver) {
mCallStateObserver = callStateObserver;
}
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
String phoneNum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
MyLog.d("outgoingNumber=" + phoneNum);
mCallStateObserver.onIpCallAvaliable();
}
}
}
自己写的,我试了可以,你试试吧。
#10
要实现电话窃听,需要监听电话的状态,方法如下:
/* 取得电话服务 */
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener listener = new PhoneStateListener(){
@Override public void onCallStateChanged(int state, String incomingNumber) {
switch (state){
case TelephonyManager.CALL_STATE_IDLE: /* 无任何状态时 */
break;
case TelephonyManager.CALL_STATE_OFFHOOK: /* 接起电话时 */
break;
case TelephonyManager.CALL_STATE_RINGING: /* 电话进来时 */
break;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
};
//监听电话的状态
telManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
在清单文件AndroidManifest.xml中添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
#11
// service内部类,监听拨打接听电话,如果有电话呼入,则暂停播放,通话结束,继续播放
public static class PhoneStatReceiver extends BroadcastReceiver {
private static boolean bPlayingFlg = false;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
// 呼出电话
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
MusicDemo.mbSeekBarUpdateFlg = false; // 停止更新播放进度
}
}
} else {
// 呼入电话
TelephonyManager tm =
(TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
switch (tm.getCallState()) {
case TelephonyManager.CALL_STATE_RINGING:
// 当前是来电
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
}
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
case TelephonyManager.CALL_STATE_IDLE: // 挂机 Device call state: No activity.
if (bPlayingFlg) {
// 恢复播放
pauseToPlay();
MusicDemo.mbSeekBarUpdateFlg = true; // 更新播放进度
bPlayingFlg = false;
}
break;
}
}
}
}
自己写的监听电话拨出和呼入状态,完全没问题。
在manifest中增加权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
#12
http://blog.csdn.net/mawl2002/archive/2010/12/11/6070056.aspx
我博客中有,写的是基于源码开发的。
我博客中有,写的是基于源码开发的。
#13
ameyume
(雨夢),
// 呼出电话
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
MusicDemo.mbSeekBarUpdateFlg = false; // 停止更新播放进度
}
}
}
你呼出电话后,暂停音乐。可是当你挂完电话,声音怎么开呢,在哪里开。
(雨夢),
// 呼出电话
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
MusicDemo.mbSeekBarUpdateFlg = false; // 停止更新播放进度
}
}
}
你呼出电话后,暂停音乐。可是当你挂完电话,声音怎么开呢,在哪里开。
#1
使用 android.telephony.PhoneStateListener
#2
这方法不行的
#3
这方法不行的,
#4
没问题啊,哪里不行了
#5
我试过,用真机测试,当接通的时候PhoneStateListener没反应
#6
off hook状态,有反应啊,你什么机器,固件和型号
#7
实现不了。我花了很长时间去研究过,网上很多方法都试过,都不行,唯一可以的就是改底层。你看log可以看出,当接通了系统会有反应,但是这个函数是不公开的,要改我觉得要重写phone类
#8
不用改底层,取得TelephonyManager,监听CALL_STATE_RINGING就可以
#9
拨入电话监听:
import android.os.RemoteException;
import android.telephony.PhoneStateListener;
import com.android.internal.telephony.ITelephony;
public class IncomingCallListener extends PhoneStateListener {
private CallStateObserver mCallStateListener = null;
private ITelephony mPhone;
public IncomingCallListener(CallStateObserver callStateListener, ITelephony phone) {
mCallStateListener = callStateListener;
mPhone = phone;
}
public void onCallStateChanged(int state, String incomingNumber) {
MyLog.d("incomingNumber="+incomingNumber);
mCallStateListener.onPhoneRinging(incomingNumber);
try {
mPhone.answerRingingCall();
// mPhone.showCallScreen();
// mPhone.showCallScreenWithDialpad(false);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
拨出电话监听:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class OutgoingCallReceiver extends BroadcastReceiver {
private CallStateObserver mCallStateObserver = null;
public OutgoingCallReceiver(CallStateObserver callStateObserver) {
mCallStateObserver = callStateObserver;
}
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
String phoneNum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
MyLog.d("outgoingNumber=" + phoneNum);
mCallStateObserver.onIpCallAvaliable();
}
}
}
自己写的,我试了可以,你试试吧。
import android.os.RemoteException;
import android.telephony.PhoneStateListener;
import com.android.internal.telephony.ITelephony;
public class IncomingCallListener extends PhoneStateListener {
private CallStateObserver mCallStateListener = null;
private ITelephony mPhone;
public IncomingCallListener(CallStateObserver callStateListener, ITelephony phone) {
mCallStateListener = callStateListener;
mPhone = phone;
}
public void onCallStateChanged(int state, String incomingNumber) {
MyLog.d("incomingNumber="+incomingNumber);
mCallStateListener.onPhoneRinging(incomingNumber);
try {
mPhone.answerRingingCall();
// mPhone.showCallScreen();
// mPhone.showCallScreenWithDialpad(false);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
拨出电话监听:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class OutgoingCallReceiver extends BroadcastReceiver {
private CallStateObserver mCallStateObserver = null;
public OutgoingCallReceiver(CallStateObserver callStateObserver) {
mCallStateObserver = callStateObserver;
}
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
String phoneNum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
MyLog.d("outgoingNumber=" + phoneNum);
mCallStateObserver.onIpCallAvaliable();
}
}
}
自己写的,我试了可以,你试试吧。
#10
要实现电话窃听,需要监听电话的状态,方法如下:
/* 取得电话服务 */
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener listener = new PhoneStateListener(){
@Override public void onCallStateChanged(int state, String incomingNumber) {
switch (state){
case TelephonyManager.CALL_STATE_IDLE: /* 无任何状态时 */
break;
case TelephonyManager.CALL_STATE_OFFHOOK: /* 接起电话时 */
break;
case TelephonyManager.CALL_STATE_RINGING: /* 电话进来时 */
break;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
};
//监听电话的状态
telManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
在清单文件AndroidManifest.xml中添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
#11
// service内部类,监听拨打接听电话,如果有电话呼入,则暂停播放,通话结束,继续播放
public static class PhoneStatReceiver extends BroadcastReceiver {
private static boolean bPlayingFlg = false;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
// 呼出电话
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
MusicDemo.mbSeekBarUpdateFlg = false; // 停止更新播放进度
}
}
} else {
// 呼入电话
TelephonyManager tm =
(TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
switch (tm.getCallState()) {
case TelephonyManager.CALL_STATE_RINGING:
// 当前是来电
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
}
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
case TelephonyManager.CALL_STATE_IDLE: // 挂机 Device call state: No activity.
if (bPlayingFlg) {
// 恢复播放
pauseToPlay();
MusicDemo.mbSeekBarUpdateFlg = true; // 更新播放进度
bPlayingFlg = false;
}
break;
}
}
}
}
自己写的监听电话拨出和呼入状态,完全没问题。
在manifest中增加权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
#12
http://blog.csdn.net/mawl2002/archive/2010/12/11/6070056.aspx
我博客中有,写的是基于源码开发的。
我博客中有,写的是基于源码开发的。
#13
ameyume
(雨夢),
// 呼出电话
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
MusicDemo.mbSeekBarUpdateFlg = false; // 停止更新播放进度
}
}
}
你呼出电话后,暂停音乐。可是当你挂完电话,声音怎么开呢,在哪里开。
(雨夢),
// 呼出电话
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
if (null != mMediaPlayer) {
if (mMediaPlayer.isPlaying()) {
bPlayingFlg = true;
pause(); // 暂停播放
MusicDemo.mbSeekBarUpdateFlg = false; // 停止更新播放进度
}
}
}
你呼出电话后,暂停音乐。可是当你挂完电话,声音怎么开呢,在哪里开。