Obtain information about the application and mobile phone installation: application version number, mobile phone model, mobile phone brand, Android system version number, and version number android

Source: Internet
Author: User

Obtain information about the application and mobile phone installation: application version number, mobile phone model, mobile phone brand, Android system version number, and version number android
/**
* User-Agent
*
* @ Return user-agent
*/
Public String getUser_Agent (){
String ua = "Android;" + getOSVersion () + ";" + getVersion () + ";"
+ GetVendor () + "-" + getDevice ();

Return ua;
}

/**
* Device model name, e. g: GT-I9100
*
* @ Return the user_Agent
*/
Public String getDevice (){
Return Build. MODEL;
}


/**
* Device factory name, e. g: Samsung
*
* @ Return the vENDOR
*/
Public String getVendor (){
Return Build. BRAND;
}


/**
* @ Return the SDK version
*/
Public int getSDKVersion (){
Return Build. VERSION. SDK_INT;
}


/**
* @ Return the OS version
*/
Public String getOSVersion (){
Return Build. VERSION. RELEASE;
}



/**
* Retrieves application's version number from the manifest
*
* @ Return versionName
*/
Public String getVersion (){
String version = "0.0.0 ";
Try {
PackageInfo packageInfo = getPackageManager (). getPackageInfo (
GetPackageName (), 0 );
Version = packageInfo. versionName;
} Catch (NameNotFoundException e ){
E. printStackTrace ();
}


Return version;
}
How to obtain the app version number in Android

Application scenarios: 1. display the application version number on the interface; 2. Start the application and check whether the application is the latest version in the background. In the preceding scenario, the application version must be automatically obtained in the program. Idea Introduction: In Android, the application version is in AndroidManifest. the PackageInfo class encapsulates all information obtained from the configuration file and describes the overall information of the Package content, you can use the versionName attribute of the PackageInfo object to obtain the application version number. How can I obtain the PackageInfo object? You can obtain the PackageManager object. PackageManager is a class used to retrieve information about related application packages installed on devices. The getPackageInfo method in the PackageManager object can obtain the PackageInfo object. This method requires two parameters: application package name and condition. Generally, the package name of an application can be obtained through the getPackageName () method of Activity or Context (Activity inherited from Context). However, many settings can be added, usually set to 0. Finally, the PackageManager object is obtained. The Context object provides the getPackageManager () method to obtain the object. In summary, the template code is as follows: (Note that the encapsulated method is located in an Activity, so this is used directly to replace the Context object) 1/** 2 * Get version 3 * @ return current application version 4 */5 publicString getVersion () {6try {7 PackageManager manager = this. getPackageManager (); 8 PackageInfo = manager. getPackageInfo (this. getPackageName (), 0); 9 String version = info. versionName; 10returnthis. getString (R. string. version_name) + version; 11} catch (Exception e) {12

How does the android system obtain the imei number and the mobile phone model and system version number?

/***** Creation date 05:02:47 **/package net. sunniwell. app; import android. app. activity; import android. OS. bundle; import android. telephony. cellLocation; import android. telephony. phoneStateListener; import android. telephony. telephonyManager; public class TelManager extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); TelephonyMa Nager tm = (TelephonyManager) this. getSystemService (TELEPHONY_SERVICE);/** call status: * 1. tm. CALL_STATE_IDLE = 0 no activity * 2. tm. CALL_STATE_RINGING = 1 bell * 3. tm. CALL_STATE_OFFHOOK = 2 disconnect */tm. getCallState (); // int/** phone location: **/tm. getCellLocation (); // CellLocation/** unique device ID: * IMEI of the GSM mobile phone and MEID of the CDMA mobile phone. * Return null if device ID is not available. */tm. getDeviceId (); // String/** software version number of the device: * e. g.: the IMEI/ SV (software version) for GSM phones. * Return null if the software version is not available. */tm. getDeviceSoftwareVersion (); // String/** mobile phone number: * MSISDN of the GSM mobile phone. * Return null if it is unavailable. */tm. getLine1Number (); // String/** nearby phone information: * type: List <NeighboringCellInfo> * permission required: android. manifest. permission # ACCESS_COARSE_UPDATES */tm. getNeighboringCellInfo (); // List <NeighboringCellInfo>/** get I SO Standard Country Code, that is, the international long-distance area code. * Note: it is valid only after the user has registered the network. * The results may be unreliable in CDMA networks. */Tm. getNetworkCountryIso (); // String/** MCC + MNC (mobile country code + mobile network code) * Note: only when using ...... remaining full text>

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.