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:
i
To listen to Android calls and answer calls, you only need to write a receiver inherited from broadcastreceiverimport android in step 2. app. service; import android. content. broadcastreceiver; import android. content. context; import android. content. intent; import android. telephony. telephonymanager; import android. util. log; public class phonestatebroadcastreceiver extends broadcastreceiver {Private Static final string tag = "phonestatebroadcas
Android and androidsdk
Android determines the SIM card status and whether the SIM card is inserted.For example, determine the preferred network type based on the SIM.
SIM card status
/*** Determine whether the SIM card is included ** @ return status */public static boolean hasSimCard () {Context context = App. getAppContext (); TelephonyManager telMgr = (TelephonyManager) context. getSystemService (Context
Android-determine SIM card status
Android determines the SIM card status and whether the SIM card is inserted.For example, determine the preferred network type based on the SIM.
SIM card status
/*** Determine whether the SIM card is included ** @ return status */public static boolean hasSimCard () {Context context = App. getAppContext (); TelephonyManager telMgr = (TelephonyManager) context. getSystemServic
Android development-Get mobile phone SIM card information, androidsim
TelephonyManager is a service class that manages the call status and network information of a mobile phone. It provides a large number of getXxx () methods to obtain information about the telephone network.
TelephonyManager class overview:
It can be used to access telephone service information on a device. Applications can use this class
The path to the java siege lion (Android)-MP3, MP4, photography, internationalization, style themes, image movement and scaling, android-mp3
I. MP3 player
View the Android API documentation to see the MediaPlayer status transition diagram:
Exercise:
Package com.shellwaygateplayer; import java. io. file; import java. io. IOException; import android. support. v7.app. actionBarActivity; import android. telephony. phoneStateListener; import android. telephony.
players of Xiao Wu, because a good application software should take into account various situations. For the music player, if a call is made during the playing of music, it may be "people who will never call you". If your music is still playing in the background at this time, I think you will go crazy, people who will never call you may never call you. This is just a joke, so you have to consider this situation. As long as you call, the player should be able to pause so that you can make a call
Note: According to the Android security mechanism, when using Telephonymanager, you must add the Androidmanifest.xml in theName= "Read_phone_state"/> cannot obtain permission from the system.
Android development platform, you can get the local number through Telephonymanager.
Cases
The code is as follows
Copy Code
Private String Getphonenumber () {
The realization of mobile phone status monitoring, mainly rely on two categories: Telephonemanger and Phonestatelistener.
Telephonsemanger provides a way to obtain information about the basic services of a mobile phone. So the application can use Telephonymanager to detect the basic service of the mobile phone. Applications can register listener to listen for changes to the phone's status. We cannot instantiate the
The first method:
Get the IMSI code of the mobile phone, and judge that China Mobile \ Chinese Unicom Telecom
Telephonymanager Telmanager = (telephonymanager) getsystemservice (context.telephony_service);
/** gets the SIM card's IMSI code
* SIM card Unique ID: IMSI International Mobile User identification Code (imsi:international Mobile Subscriber identification number) is a sign that distinguishes
Android determines which mobile operator the SIM card belongs to
The first method:
Get the IMSI code of the mobile phone, and judge that China Mobile \ Chinese Unicom Telecom
Telephonymanager Telmanager = (telephonymanager) getsystemservice (context.telephony_service);
/** gets the SIM card's IMSI code
* SIM card Unique ID: IMSI International Mobile User identification Code (imsi:internat
also wrote a class implementation to get the operatorLayout file:Simcardinfo.java:/** * @author Yazhizhao * 20142014-10-22 morning 9:13:04 */package com.example.android_sms;import android.content.Context; Import Android.telephony.telephonymanager;import android.util.log;/** * @author Yazhizhao 20142014-10-22 9:13:04 */ public class Simcardinfo {/** * Telephonymanager provides access to information about the communication service on the device. Applic
(Activity_service. Equals (name )){
Returngetactivitymanager ();
} Else if (Telephony_service. Equals (name )){
Return gettelephonymanager ();
..... Below
Private telephonymanager gettelephonymanager (){
Synchronized (msync ){
If (mtelephonymanager = NULL ){
Mtelephonymanager = new telephonymanager (getoutercontext ());
}
}
Return mtelephonymanager;
}
The following is the construction method of the
mistaken, you can use phonestatelistener. Many applications use phonestatelistener to listen for incoming call power. phonestatelistener can also listen for network disconnection, connection, and connection success. Let's look at the code. Java code: Final telephonymanager mtelephonymgr = (telephonymanager) getsystemservice (context. telephony_service );Mtelephonymgr. listen (New phonestatelistener () {@ o
phones.Currently, most Android mobile phones support WIFI,GSM, 3G network communicationBut you can select only one connection method each time you link to the network,For example, a carrier must also require a specific network environment (CMWAP, CTWAP, etc.) to switch the network, you must first disable the existing network,Then start a new network. The conversion process takes some time,At this time, you may also need to know whether the network connection is successful and then automatically
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.