Home>

The first code:

string phoneinfo="product:" + android.os.build.product;
phoneinfo +=", cpu_abi:" + android.os.build.cpu_abi;
phoneinfo +=", tags:" + android.os.build.tags;
phoneinfo +=", version_codes.base:" + android.os.build.version_codes.base;
phoneinfo +=", model:" + android.os.build.model;
phoneinfo +=", sdk:" + android.os.build.version.sdk;
phoneinfo +=", version.release:" + android.os.build.version.release;
phoneinfo +=", device:" + android.os.build.device;
phoneinfo +=", display:" + android.os.build.display;
phoneinfo +=", brand:" + android.os.build.brand;
phoneinfo +=", board:" + android.os.build.board;
phoneinfo +=", fingerprint:" + android.os.build.fingerprint;
phoneinfo +=", id:" + android.os.build.id;
phoneinfo +=", manufacturer:" + android.os.build.manufacturer;
phoneinfo +=", user:" + android.os.build.user;
textview t=(textview) findviewbyid (r.id.main_phoneinfo);
t.settext (phoneinfo);

The second code:

private string gethandsetinfo () {
string handsetinfo =
"Phone Model:" + android.os.build.model +
", Sdk version:" + android.os.build.version.sdk +
", System version:" + android.os.build.version.release +
", Software version:" + getappversionname (mainactivity.this);
return handsetinfo;
}
//Get the current version number
private string getappversionname (context context) {
string versionname="";
try {
packagemanager packagemanager=context.getpackagemanager ();
packageinfo packageinfo=packagemanager.getpackageinfo ("cn.testgethandsetinfo", 0);
versionname=packageinfo.versionname;
if (textutils.isempty (versionname)) {
return "";
}
} catch (exception e) {
e.printstacktrace ();
}
return versionname;
}

The third code:Get the phone model,system version,app version number, etc.Specific code:

The mainactivity is as follows:

package cn.testgethandsetinfo;
import android.os.bundle;
import android.text.textutils;
import android.widget.textview;
import android.app.activity;
import android.content.context;
import android.content.pm.packageinfo;
import android.content.pm.packagemanager;
/**
* Demo description:
* Get phone model,system version,app version number and other information
* /
public class mainactivity extends activity {
private textview mtextview;
@override
protected void oncreate (bundle savedinstancestate) {
super.oncreate (savedinstancestate);
setcontentview (r.layout.main);
init ();
}
private void init () {
mtextview=(textview) findviewbyid (r.id.textview);
mtextview.settext (gethandsetinfo ());
}
private string gethandsetinfo () {
string handsetinfo =
"Mobile Model:" + android.os.build.model +
", sdk version:" + android.os.build.version.sdk +
", System version:" + android.os.build.version.release +
", Software version:" + getappversionname (mainactivity.this);
return handsetinfo;
}
//Get the current version number
private string getappversionname (context context) {
string versionname="";
try {
packagemanager packagemanager=context.getpackagemanager ();
packageinfo packageinfo=packagemanager.getpackageinfo ("cn.testgethandsetinfo", 0);
versionname=packageinfo.versionname;
if (textutils.isempty (versionname)) {
return "";
}
} catch (exception e) {
e.printstacktrace ();
}
return versionname;
}
}

main.xml is as follows:

<relativelayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<textview
android:id="@ + id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@ string/hello_world"
android:layout_centerinparent="true"
/>
</relativelayout>

The last piece of code:

phoneinfo="product:" + android.os.build.product;
    phoneinfo +=", cpu_abi:" + android.os.build.cpu_abi;
    phoneinfo +=", tags:" + android.os.build.tags;
    phoneinfo +=", version_codes.base:" + android.os.build.version_codes.base;
    phoneinfo +=", model:" + android.os.build.model;
    phoneinfo +=", sdk:" + android.os.build.version.sdk;
    phoneinfo +=", version.release:" + android.os.build.version.release;
    phoneinfo +=", device:" + android.os.build.device;
    phoneinfo +=", display:" + android.os.build.display;
    phoneinfo +=", brand:" + android.os.build.brand;
    phoneinfo +=", board:" + android.os.build.board;
    phoneinfo +=", fingerprint:" + android.os.build.fingerprint;
    phoneinfo +=", id:" + android.os.build.id;
    phoneinfo +=", manufacturer:" + android.os.build.manufacturer;
    phoneinfo +=", user:" + android.os.build.user;
  • Previous VS2015 running Cordova project exception solution after upgrading to Update2
  • Next Yii Purifier CHtmlPurifier usage example (filtering bad code)