Android获取手机型号,系统版本,App版本号等信息

news/2024/7/7 21:01:47

MainActivity如下:

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描述:
 * 获得手机型号,系统版本,App版本号等信息
 */
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=
	  "手机型号:" + android.os.Build.MODEL + 
	  ",SDK版本:" + android.os.Build.VERSION.SDK + 
	  ",系统版本:" + android.os.Build.VERSION.RELEASE+
	  ",软件版本:"+getAppVersionName(MainActivity.this); 
	  return handSetInfo;

  }
  //获取当前版本号
  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如下:

<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>



转载地址: http://www.cnblogs.com/dyllove98/archive/2013/06/10/3131143.html




http://www.niftyadmin.cn/n/3648892.html

相关文章

如何在Ubuntu 18.04上使用PHP在MySQL中实现分页

The author selected the the Apache Software Foundation to receive a donation as part of the Write for DOnations program. 作者选择了Apache软件基金会作为Write for DOnations计划的一部分来接受捐赠。 介绍 (Introduction) Pagination is the concept of constrainin…

自定义view——仿支付宝咻一咻

效果图 这里首先我们我们做一个波波&#xff0c;思路是这样&#xff1a;①设置圆圈的画笔②绘制图片到中心位置&#xff0c;并设置波的大小为图片宽度的一半③hanlder中设置波的半径不断变大&#xff0c;当半径大于画布宽度一半的时候设置半径为图片的宽度一半 public class X…

Android 5.0 权限管理导致的apk安装失败解决方案

在刚5.0出来的时候&#xff0c; 很多apk 在 5.0上会安装失败&#xff0c; 原因其实是&#xff0c; 安装的apk 中的 自定义权限 与 手机上面已经有的app 的自定义权限相同。 问题&#xff1a;当初有做 百度地图的同事就遇到了这个问题&#xff0c; app一直安装失败。需要去掉权限…

如何在CentOS 7上设置Eclipse Theia Cloud IDE平台

介绍 (Introduction) With developer tools moving to the cloud, adoption of cloud IDE (Integrated Development Environment) platforms is growing. Cloud IDEs are accessible from every type of modern device through web browsers, and they offer numerous advantag…

【Zookeeper】使用Curator操作Zookeeper

简介 Curator 是 Apache ZooKeeper 的Java客户端库。 Zookeeper现有常见的Java API如&#xff1a;原生JavaAPI、Curator、ZkClient等。 添加依赖 <dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId&…

写一套IOC注解框架

首先控件属性注入 //Target(ElementType.FIELD) 代表Annotion的值 FIELD属性 TYPE类上 METHOD方法 CONSTRUCTOR构造函数 Target(ElementType.FIELD) //Retention(RetentionPolicy.RUNTIME) 运行时生效 CLASS编译时生效 SOURCE源码资源 Retention(RetentionPolicy.RUNTIME) …

乐视揭秘Android5.0手机APP安装失败真相

Android5 0正在成为手机行业的新趋势&#xff0c;越来越多的手机厂商开始推出Android5 0系统的新一代手机。Android5.0正在成为手机行业的新趋势&#xff0c;越来越多的手机厂商开始推出Android5.0系统的新一代手机。乐视更是一口气推出三大旗舰手机&#xff0c;三款手机搭载的…

如何在CentOS 7上安装和使用TimescaleDB

The author selected the Computer History Museum to receive a donation as part of the Write for DOnations program. 作者选择“ 计算机历史博物馆”作为“ Write for DOnations”计划的一部分接受捐赠。 介绍 (Introduction) Many applications, such as monitoring sys…