Telephony_service for systemservice Learning

Source: Internet
Author: User

Telephonymanager mtelephonymgr = (telephonymanager) getsystemservice (context. telephony_service );

Telephonymanager provides a method for obtaining mobile phone information, including call status, network connection, and carrier information,

The following example shows how telephonymanager monitors the call status:

import android.os.Bundle;import android.app.Activity;import android.content.BroadcastReceiver;import android.content.Context;  import android.content.IntentFilter;import android.telephony.PhoneStateListener;  import android.telephony.TelephonyManager;  import android.util.Log;  import android.widget.TextView;  public class MainActivity extends Activity {  private static final String TAG = "Telephony";  TextView view = null;  @Override  protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      TelephonyManager mTelephonyMgr =         (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);      mTelephonyMgr.listen(new TeleListener(),PhoneStateListener.LISTEN_CALL_STATE);      view = new TextView(this);      view.setText("listen the state of phone\n");      setContentView(view);  }      class TeleListener extends PhoneStateListener {       @Override        public void onCallStateChanged(int state, String incomingNumber)        {            super.onCallStateChanged(state, incomingNumber);            switch (state) {                case TelephonyManager.CALL_STATE_IDLE: {                   Log.d(TAG, "CALL_STATE_IDLE");                   view.append("CALL_STATE_IDLE " + "\n");                   break;                  }              case TelephonyManager.CALL_STATE_OFFHOOK: {                   Log.d(TAG, "CALL_STATE_OFFHOOK");                   view.append("CALL_STATE_OFFHOOK" + "\n");                   break;                  }             case TelephonyManager.CALL_STATE_RINGING: {                     Log.d(TAG, "CALL_STATE_RINGING");                     view.append("CALL_STATE_RINGING" + "\n");                  break;                  }          default:          Log.d(TAG, " the statu is"+state);        break;            }          }     }  } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.