This article is an example of Android to check whether the phone and wireless connection to the implementation code, share for everyone to reference. The specific methods are as follows:
Method One:
The main functional code is as follows:
Copy Code code as follows:
Connectivitymanager manager = (Connectivitymanager) getsystemservice (Context.connectivity_service);
Networkinfo info = Manager.getactivenetworkinfo ();
if (Info!=null info.isconnected ()) {
return true;
}el
) {//
SYSTEM.OUT.PRINTLN (i + "= = = State = =" + networkinfo[i].getstate ());
SYSTEM.OUT.PRINTLN (i + "= = = Type = = =" + Networkinfo[i].gettypename ()); JudgeWhether the current network state is a connection state if (anetworkinfo.getstate () = = NetworkInfo.State.CONNECTED) {return true;
}}} return false;
/** * Determine if WiFi is open * @param context * @return/public static Boolean iswifienabled
Connectivitymanager mgrconn = (connectivitymanager) context. Getsystemserv
The example of this article summarizes the common code snippets for Android development. Share to everyone for your reference, specific as follows:
1. Picture rotation
Bitmap bitmaporg = Bitmapfactory.decoderesource (This.getcontext (). Getresources (), r.drawable.moon);
Matrix matrix = new Matrix ();
Matrix.postrotate (-90);//rotation angle
Bitmap resizedbitmap = Bitmap.createbitmap (bitmaporg, 0, 0,
Bitmaporg.getwidth (), Bitmaporg.getheight (), Matrix, true);
Bitmapdrawable
How to get the native phone number on Android, and now Android provides an API to read the number that was cured on the early SIM card,
Copy Code code as follows:
Private String Getphonenumber () {
Telephonymanager Mtelephonymgr;
Mtelephonymgr = (Telephonymanager) getsystemservice (Context.telephony_service);
return Mtelephonymgr.getline1number ();
}
The Getphonenumber method above returns
Copy code code as follows:
Connectivitymanager mconnectivity = (connectivitymanager) getsystemservice (Context.connectivity_service);
Telephonymanager mtelephony = (telephonymanager) this.getsystemservice (Telephony_service);
Check network connection, if no network is available, do not need to do networking operations, etc.
Networkinfo info = Mconnectivity.getactivenetworkinfo ();
i
Create a broadcast event receiver and register this file in the manifest file, filtering the intent toAndroid.intent.action.PHONE_STATEIn the IntelliJ because did not prompt thought that does not have this, actually has, increases the permissionAndroid.permission.READ_PHONE_STATE
android:name=".receiver.CallReceiver">
android:name="android.intent.action.PHONE_STATE"/>
android:name="android.permission
Add Permission settingsDetermines whether the current device is an emulator. If true, it is currently the emulator, not returning falseprivate static Boolean Isemulator (context context) {try{Telephonymanager TM = (Telephonymanager) context.getsystemservice (Context.telephony_service);String IMEI = Tm.getdeviceid ();if (IMEI = null (imei.equals ("000000000000000") | | imei.equals ("098675694745850"))) {ret
In the original: Android system get IMEI number Mobile number IMSI numberSource code: Http://www.zuidaima.com/share/1550463673584640.htmFirst, get IMEI numberTelephonymanager telephonymanager= (Telephonymanager) This.getsystemservice (Context.telephony_service);String Imei=telephonymanager.getdeviceid ();Permissions Required:Second, get mobile phone numberTelephonymanager.getline1number ();Some phones can b
) when the activity is toggled; Break } }} Set Interface Wizard Face 2Requirement function: 1. Bind SIM card 2. Processing of the CheckBox State 3. Previous step, next click on the implementation of the function
Binding SIM card
When the user clicks on "Bind SIM card", the corresponding processing logic is triggered, the serial number of the current SIM card is obtained, and the serial number is accessed into the sharepreference.To get the SIM card serial number of your ph
Problem descriptionTitle, if Java can do it better. Hope that we can provide the code, not to give a train of thought also line. Solutions 1It's not the way it is.private void Loadphonestatus (){Telephonymanager phonemgr= (Telephonymanager) This.getsystemservice (Context.telephony_service);Txtphonemodel.settext (Build.model); Phone modelTxtsdkversion.settext (Build.VERSION.SDK);//SDK version numberTxtosvers
Telephonymanager is a service class that manages mobile phone call status and telephone network information, which provides a large number of getxxx () methods to obtain information about the telephone network. the details of Telephonymanager can be referenced: Android development to get SIM card information for mobile phoneProgram Run Result:
Log_phone file:Application Examples:
Package Com.jph
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.