Tools for obtaining mobile phone information: PhoneHelper and tools: phonehelper
PhoneHelper
Obtains basic information about a mobile phone, such as the manufacturer, firmware version, mobile phone model, mobile phone number, and screen resolution.
The Code is as follows:
Import java. io. file; import java. util. list; import java. util. regex. matcher; import java. util. regex. pattern; import android. content. context; import android. content. intent; import android. content. pm. applicationInfo; import android. content. pm. packageManager; import android.net. connectivityManager; import android.net. networkInfo; import android.net. uri; import android. OS. environment; import android. telephony. telep HonyManager; import android. text. textUtils; import android. util. displayMetrics; import android. util. typedValue; import android. view. display; import android. view. gravity; import android. view. windowManager; import android. widget. toast; public class PhoneHelper {private Context context = App. getInstance (); private static PhoneHelper util; public static PhoneHelper getInstance () {if (util = null) {util = ne W PhoneHelper ();} return util;} private PhoneHelper () {super ();}/*** production merchant ** @ return */public String getManufacturer () {return android. OS. build. MANUFACTURER;}/*** obtain the firmware version ** @ return */public String getRelease () {return android. OS. build. VERSION. RELEASE;}/*** get the mobile phone model ** @ return */public String getModel () {return android. OS. build. MODEL;}/*** get the mobile phone brand ** @ return */public String g EtBrand () {return android. OS. build. BRAND;}/*** get the mobile phone operator */public String getSimOperatorName () {TelephonyManager tm = (TelephonyManager) context. getSystemService (Context. TELEPHONY_SERVICE); return tm. getSimOperatorName ();}/*** get the mobile phone number of the local machine. * @ return */public String getThisPhoneNumber () cannot be obtained if no SIM card is installed or no mobile phone number is written to the SIM card () {TelephonyManager tm = (TelephonyManager) context. getSystemService (Context. TELE PHONY_SERVICE); String number = tm. getLine1Number (); return number;}/*** whether the phone number is ** @ param phonenumber * @ return */public boolean isPhoneNumber (String phonenumber) {Pattern pa = Pattern. compile ("^ [1] [3, 4, 5, 8, 7] [0-9] {9} $"); Matcher ma = pa. matcher (phonenumber); return ma. matches ();}/*** call ** @ param phone * @ param context */public void doPhone (String phone) {Intent phoneIntent = new In Tent (Intent. ACTION_DIAL, Uri. parse ("tel:" + phone); context. startActivity (phoneIntent);}/*** send a text message ** @ param phone * @ param content * @ param c */public void doSMS (String phone, String content) {Uri uri = null; if (! TextUtils. isEmpty (phone) uri = Uri. parse ("smsto:" + phone); Intent intent = new Intent (Intent. ACTION_SENDTO, uri); intent. putExtra ("sms_body", content); context. startActivity (intent);}/*** get screen information * getScreenDisplayMetrics (). heightPixels screen height * getScreenDisplayMetrics (). widthPixels screen width * @ return */public DisplayMetrics getScreenDisplayMetrics () {WindowManager manager = (WindowManager) context. GetSystemService (Context. WINDOW_SERVICE); DisplayMetrics displayMetrics = new DisplayMetrics (); Display display = manager. getdefadisplay display (); display. getMetrics (displayMetrics); return displayMetrics;}/*** screen resolution ** @ param drame * @ return */public float getDip () {return TypedValue. applyDimension (TypedValue. COMPLEX_UNIT_DIP, 1, context. getResources (). getDisplayMetrics ();}/*** install apk */pub Lic void instance (File file) {Intent intent = new Intent (); intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); intent. setAction (android. content. intent. ACTION_VIEW); intent. setDataAndType (Uri. fromFile (file), "application/vnd. android. package-archive "); context. startActivity (intent);}/*** whether ** @ param packageName * @ return */public boolean isInstall (String packageName) {PackageManager packageM is installed Anager = context. getPackageManager (); List <ApplicationInfo> packs = packageManager. getInstalledApplications (PackageManager. GET_ACTIVITIES); for (ApplicationInfo: packs) {if (info. packageName. equals (packageName) return true;} return false;}/*** checks whether the Network is available ** @ return */public boolean isNetworkConnected () {ConnectivityManager cm = (ConnectivityManager) context. getSystemService (Context. CONNECTIVITY_SERVICE); NetworkInfo ni = cm. getActiveNetworkInfo (); return ni! = Null & ni. isConnected ();}/*** place Toast above the screen ** @ param message */public void show (String message) {Toast toast = Toast. makeText (context, message, Toast. LENGTH_LONG); toast. setGravity (Gravity. TOP, 0, (getScreenDisplayMetrics (). heightPixels/5); toast. show ();}/*** open ** @ param activity * @ param url */public void openWeb (String url) {Intent intent = new Intent ("android. intent. actio N. VIEW ", Uri. parse (url); intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); context. startActivity (intent);}/*** whether an external memory card exists ** @ return */public boolean isExistExternalStore () {if (Environment. getExternalStorageState (). equals (Environment. MEDIA_MOUNTED) {return true;} else {return false;}/*** get the SD card path ** @ return */public String getExternalStorePath () {if (isExistExternalStore ()) {return Environment. getExternalStorageDirectory (). getAbsolutePath ();} return null;}/*** get the network type, 0 is unknown or not connected to the network, 1 is WIFI, 2 is 2g, 3 is 3g, 4 is 4g * @ return */public int getNetType () {ConnectivityManager connectMgr = (ConnectivityManager) context. getSystemService (Context. CONNECTIVITY_SERVICE); int type = 0; NetworkInfo info = connectMgr. getActiveNetworkInfo (); if (info = null |! Info. isConnected () {return type;} switch (info. getType () {case ConnectivityManager. TYPE_WIFI: type = 1; break; case ConnectivityManager. TYPE_MOBILE: type = getNetworkClass (info. getSubtype (); break; default: type = 0; break;} return type ;} /*** determine the data connection type * @ param networkType * @ return */public int getNetworkClass (int networkType) {switch (networkType) {case TelephonyManager. NETWORK_TYPE_GPRS: case TelephonyManager. NETWORK_TYPE_EDGE: case TelephonyManager. NETWORK_TYPE_CDMA: case TelephonyManager. NETWORK_TYPE_1xRTT: case TelephonyManager. NETWORK_TYPE_IDEN: case TelephonyManager. NETWORK_TYPE_UNKNOWN: return 2; case TelephonyManager. NETWORK_TYPE_UMTS: case TelephonyManager. NETWORK_TYPE_EVDO_0: case TelephonyManager. NETWORK_TYPE_EVDO_A: case TelephonyManager. NETWORK_TYPE_HSDPA: case TelephonyManager. NETWORK_TYPE_HSUPA: case TelephonyManager. NETWORK_TYPE_HSPA: case TelephonyManager. NETWORK_TYPE_EVDO_ B: case TelephonyManager. NETWORK_TYPE_EHRPD: return 3; case TelephonyManager. NETWORK_TYPE_LTE: return 4; default: return 0 ;}}}