Demo download
Finally , the above examples are all sourced from Android worry-free, please go to the application treasure or pea pod to download: http://android.myapp.com/myapp/detail.htm?apkName=com.shandong.mm. androidstudy , the source code example document is exhausted.
The comments are all in the code: [size=xx-large][/size]
package mm.shandong.com.testdevicemessage; import android.Manifest; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.view.View; import android.view.WindowManager; import android.widget.TextView; import mm.shandong.com.testdevicemessage.util.CPUUtil; import mm.shandong.com.testdevicemessage.util.MemeryUtil; public class TestDeviceMessageActivity extends AppCompatActivity { TextView textViewMessage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView(R.layout.activity_test_device_message); textViewMessage = (TextView) findViewById(R.id.textViewMessage); } public void getMetric(View view) { WindowManager wm = (WindowManager) getSystemService (WINDOW_SERVICE); DisplayMetrics displayMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(displayMetrics); textViewMessage.setText("宽度:" + displayMetrics.widthPixels + " 高度: " + displayMetrics.heightPixels); } public void getCPUNumber(View view) { textViewMessage.setText("CPU name is:" + CPUUtil.getCpuName() + "CPU maximum frequency:" + CPUUtil.getMaxCpuFreq().toString() + "CUP minimum frequency:" + CPUUtil.getMinCpuFreq() + "CUP current frequency:" + CPUUtil.getCurCpuFreq()); } public void getStorage(View view) { String str = "Memory size:" + MemeryUtil.getTotalMemory() + " \n"; str = str + "SD Card Size: " + MemeryUtil.getSDCardMemory()[0] + " SD Card Available Size: " + MemeryUtil.getSDCardMemory()[1] + "\n"; str = str + "ROM size: " + MemeryUtil.getRomMemroy()[0] + " ROM available size: " + MemeryUtil.getRomMemroy()[1]; textViewMessage.setText(str); } public void getMac(View view) { String str = "MAC:" + MemeryUtil.getOtherInfo(this)[0] + " \n"; str = str + "Boot time:" + MemeryUtil.getOtherInfo(this)[1]; textViewMessage.setText(str); } public void getMEID(View view) { TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); textViewMessage.setText(device_id); } public void getLocation(View view) { String serviceString = this.LOCATION_SERVICE; LocationManager locationManager = (LocationManager) getSystemService(serviceString); String provider = LocationManager.NETWORK_PROVIDER; // TODO: Consider calling if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling return; } Location location = locationManager.getLastKnownLocation(provider); double lat = location.getLatitude();///维度 double lng = location.getLongitude();//经度 textViewMessage.setText("Dimension is: " + lat + " Longitude is: " + lng); return; } public void getOS(View view) { textViewMessage.setText("型号: " + android.os.Build.MODEL + "," + "OS:" + android.os.Build.VERSION.SDK + "," + "Version:" + android.os.Build.VERSION.RELEASE); } public void getVN(View view) { try { int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; textViewMessage.setText("versionCode : " + versionCode + "," + "versionNmae:" + versionName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace (); } } }