zoukankan      html  css  js  c++  java
  • Android 使用Telephony API

    Android 使用Telephony API

    public class TelephonyDemo extends Activity {
        TextView textOut;
        TelephonyManager telephonyManager;
        PhoneStateListener listener;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.main);
            // Get the UI
            textOut = (TextView) findViewById(R.id.textOut);
            // 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;
                    }
                    textOut.append(String.format("
    onCallStateChanged: %s",
                            stateString));
                }
            };
            // Register the listener wit the telephony manager
            telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
        }
    }
    

     参考资料

  • 相关阅读:
    多线程
    事务的概念与四大特性(ACID)
    Error和Exception的区别
    运算符的使用与注意事项(二)
    运算符的使用与注意事项(一)
    GOJS使用--前端拓扑图
    python算法实现分治法demo
    MySQL主从复制配置
    MySQL锁
    show profile查看SQL执行生命周期
  • 原文地址:https://www.cnblogs.com/linlf03/p/3154654.html
Copyright © 2011-2022 走看看