Android Development Summary to get the call number

Source: Internet
Author: User

Create a broadcast event receiver and register this file in the manifest file, filtering the intent toAndroid.intent.action.PHONE_STATE
In the IntelliJ because did not prompt thought that does not have this, actually has, increases the permissionAndroid.permission.READ_PHONE_STATE
  
 
  1. <receiver android:name=".receiver.CallReceiver">
  2. <intent-filter>
  3. <action android:name="android.intent.action.PHONE_STATE"/>
  4. </intent-filter>
  5. </receiver>
 
   
  
  1. <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

In receiver, it is determined that the action of intent is the change of the phone state and the status of the parameter change is ringring, that is, when the phone rings, get the mobile phone number

  
 
  1. public class CallReceiver extends BroadcastReceiver {
  2. @Override
  3. /span>public void OnReceive ( context Context Span class= "pun", intent Intent ) {
  4. if telephonymanager action_phone_state_changed equals ( intent getaction && "ringing" equals ( intent getstringextra telephonymanager extra_state {
  5. String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
  6. }
  7. }
  8. }
The number that is obtained at this point is the caller ID.




















From for notes (Wiz)

Android Development Summary to get the call number

Related Article

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.