0

我听说我们不能使用 TelephonyManager 来检测来自 Android 2.3 及更高版本的来电/未接/已拨电话。这是真的?如果是的,我们是否有任何解决方法来处理电话?请建议。我急需它。

4

1 回答 1

0

检查这篇文章。这会有所帮助

你可以查询一下。

请找到使用 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"/>
于 2012-08-28T05:16:21.890 回答