我使用的是:
public void onCallStateChanged(int state, String incomingNumber)正在收听的是:
telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);我想知道呼出呼叫和呼入呼叫,但目前我只收到呼入呼叫(当状态更改为振铃时)。谁能告诉我什么时候可以检测到呼出电话及其结束
此外,还有一种方法可以在Eclipse模拟器中模拟传出调用。能够通过eclipse中的仿真器控件对传入呼叫执行此操作。
发布于 2011-07-12 13:32:20
对IntentFilter使用带有意图android.intent.action.NEW_OUTGOING_CALL字符串参数的广播侦听器,并且不要忘记在AndroidMenifest中将权限授予PROCESS_OUTGOING_CALLS。这将会起作用。每当有呼出呼叫时,都会显示一条toast消息。代码如下。
public static final String outgoing = "android.intent.action.NEW_OUTGOING_CALL" ;
IntentFilter intentFilter = new IntentFilter(outgoing);
BroadcastReceiver OutGoingCallReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
String outgoingno = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(context, "outgoingnum =" + outgoingno,Toast.LENGTH_LONG).show();
}
};
registerReceiver(brForOutgoingCall, intentFilter);发布于 2015-06-12 23:47:59
创建一个新类,假设MyPhoneReceiver,从BroadcastReceiver扩展了它,并实现了onReceive方法。
public class MyPhoneReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent){
String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
}
}在另一个类中,假设在onCreate方法中使用MainActivity.class。例如。
IntentFilter filter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
MyPhoneReceiver myPhoneReceiver = new MyPhoneReceiver();
registerReceiver(myPhoneReceiver,filter);在AndroidManifest.xml中
<receiver
android:name=".MyPhoneReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>还可以在AndroidManifest.xml中添加:
<uses-permission
android:name="android.permission.PROCESS_OUTGOING_CALLS">
</uses-permission>https://stackoverflow.com/questions/6611197
复制相似问题