我听说我们无法使用TelephonyManager来检测来自Android 2.3及更高版本的Incoming / Missed / Dialed来电。这是真的?如果是,我们是否有处理呼叫的解决方法?请建议。我迫切需要它。
答案 0 :(得分:0)
检查this帖子。它会有所帮助。
您可以查询它。
请找到使用TelephonyManager的代码。我在2.3.3中尝试过并且正在为我工作:
public class MainActivity extends Activity {
private TelephonyManager telephonyManager;
private PhoneStateListener listener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the telephony manager
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// Create a new PhoneStateListener
listener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
String stateString = "N/A";
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
stateString = "Idle";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
stateString = "Off Hook";
break;
case TelephonyManager.CALL_STATE_RINGING:
stateString = "Ringing";
break;
}
Log.i("DEMO",
String.format("\nonCallStateChanged: %s", stateString));
}
};
telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}
在Manifest中,您需要获得权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>