android获取包版本,Android获取应用名称、版本号、应用包名称,移动设备ID、MAC地址、基站信息和手机型号等详细信...
创建一个android应用(AndroidTest),所需权限如下(AndroidManifest.xml文件):
接下来是MainActivity.java文件:
package com.example.androidtest;
import org.json.JSONException;
import org.json.JSONObject;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getInfo();
}
public void getInfo() {
try {
StringBuilder strLog = new StringBuilder();
Context ctx = this.getApplicationContext();
/**
* 1.获取应用信息
*
* 要想获取更多应用相关信息请查阅PackageManager、ApplicationInfo资料
*/
// 获取应用名称
String appName = getAppName(ctx);
strLog.append("应用名称:" + appName + "\r\n");
// 获取应用包名称
String packName = getPackName(ctx);
strLog.append("应用包名称:" + packName + "\r\n");
// 获取应用版本
String verName = getVerName(ctx, packName);
strLog.append("应用版本名称:" + verName + "\r\n");
// 获取应用版本号
int verCode = getVerCode(ctx, packName);
strLog.append("应用版本号:" + verCode + "\r\n");
/**
* 2.获取设备信息
*/
// 获取手机型号
String model = getPhoneModel();
strLog.append("手机型号:" + model + "\r\n");
// 获取手机号码
String phoneNum = getLineNum(ctx);
strLog.append("手机号码:" + phoneNum + "\r\n");
// 获取移动用户标志,IMSI
String imsi = getSubscriberId(ctx);
strLog.append("IMSI:" + imsi + "\r\n");
// 获取设备ID
String devID = getDeviceID(ctx);
strLog.append("设备ID:" + devID + "\r\n");
// 获取SIM卡号
String sim = getSim(ctx);
strLog.append("SIM卡号:" + sim + "\r\n");
// 获取基站信息
SCell cellInfo = getCellInfo(ctx);
String strCell = "";
if (cellInfo != null) {
strCell = cellInfo.toJSON().toString();
}
strLog.append("基站信息:" + strCell + "\r\n");
// 获取Mac地址
String mac = getMac(ctx);
strLog.append("Mac地址:" + mac + "\r\n");
System.out.println(strLog.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取应用包名称
*/
public String getPackName(Context ctx) {
return ctx.getPackageName();
}
/**
* 获取应用版本名称
*/
public String getVerName(Context ctx, String packName) {
String verName = "";
try {
verName = ctx.getPackageManager().getPackageInfo(packName, 0).versionName;
} catch (NameNotFoundException e) {
}
return verName;
}
/**
* 获取应用版本号
*/
public int getVerCode(Context context, String packName) {
int versionCode = 0;
try {
versionCode = context.getPackageManager().getPackageInfo(packName,
0).versionCode;
} catch (NameNotFoundException e) {
}
return versionCode;
}
/**
* 获取应用名称
*/
public String getAppName(Context ctx) {
String appName = "";
try {
PackageManager packManager = ctx.getPackageManager();
ApplicationInfo appInfo = ctx.getApplicationInfo();
appName = (String) packManager.getApplicationLabel(appInfo);
} catch (Exception e) {
}
return appName;
}
/**
* 获取手机型号
*
* android.os.Build提供以下信息:
* String BOARD The name of the underlying board, like "goldfish".
* String BRAND The brand (e.g., carrier) the software is customized for, if any.
* String DEVICE The name of the industrial design.
* String FINGERPRINT A string that uniquely identifies this build.
* String HOST
* String ID Either a changelist number, or a label like "M4-rc20".
* String MODEL The end-user-visible name for the end product.
* String PRODUCT The name of the overall product.
* String TAGS Comma-separated tags describing the build, like "unsigned,debug".
* long TIME
* String TYPE The type of build, like "user" or "eng".
* String USER
*/
public String getPhoneModel() {
return android.os.Build.MODEL;
}
/**
* 获取手机号码,一般获取不到
*
* 用到的权限:
*
*
* 要想获取更多电话、数据、移动网络相关信息请查阅TelephonyManager资料
*/
public String getLineNum(Context ctx) {
String strResult = "";
TelephonyManager telephonyManager = (TelephonyManager) ctx
.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
strResult = telephonyManager.getLine1Number();
}
return strResult;
}
/**
* 获取移动用户标志,IMSI
*
* 用到的权限:
*
*/
public String getSubscriberId(Context ctx) {
String strResult = "";
TelephonyManager telephonyManager = (TelephonyManager) ctx
.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
strResult = telephonyManager.getSubscriberId();
}
return strResult;
}
/**
* 获取设备ID
*
* 用到的权限:
*
*/
public String getDeviceID(Context ctx) {
String strResult = null;
TelephonyManager telephonyManager = (TelephonyManager) ctx
.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
strResult = telephonyManager.getDeviceId();
}
if (strResult == null) {
strResult = Secure.getString(ctx.getContentResolver(),
Secure.ANDROID_ID);
}
return strResult;
}
/**
* 获取SIM卡号
*
* 用到的权限:
*
*/
public String getSim(Context ctx) {
String strResult = "";
TelephonyManager telephonyManager = (TelephonyManager) ctx
.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
strResult = telephonyManager.getSimSerialNumber();
}
return strResult;
}
/**
* 获取Wifi Mac地址
*
* 要想获取更多Wifi相关信息请查阅WifiInfo资料
*
* 用到的权限:
*
*/
public String getMac(Context ctx) {
WifiManager wifiManager = (WifiManager) ctx
.getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null) {
WifiInfo wi = wifiManager.getConnectionInfo();
return wi.getMacAddress();
}
return null;
}
/**
* 获取基站信息
*
* 用到的权限:
*
*
*/
public SCell getCellInfo(Context ctx) {
SCell cell = new SCell();
TelephonyManager tm = null;
try {
tm = (TelephonyManager) ctx
.getSystemService(Context.TELEPHONY_SERVICE);
} catch (Exception e) {
return null;
}
// IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
String IMSI = tm.getSubscriberId();
if (IMSI != null) {
if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
cell.NETWORK_TYPE = "CHINA MOBILE";
GsmCellLocation location = (GsmCellLocation) tm
.getCellLocation();
if (location == null) {
cell = null;
} else {
String operator = tm.getNetworkOperator();
if (operator.length() > 4) {
int mcc = Integer.parseInt(operator.substring(0, 3));
int mnc = Integer.parseInt(operator.substring(3));
int cid = location.getCid();
int lac = location.getLac();
cell.MCC = mcc;
cell.MNC = mnc;
cell.LAC = lac;
cell.CID = cid;
} else {
cell = null;
}
}
} else if (IMSI.startsWith("46001")) {
cell.NETWORK_TYPE = "CHINA UNICOM";
GsmCellLocation location = (GsmCellLocation) tm
.getCellLocation();
if (location == null) {
cell = null;
} else {
String operator = tm.getNetworkOperator();
if (operator.length() > 4) {
int mcc = Integer.parseInt(operator.substring(0, 3));
int mnc = Integer.parseInt(operator.substring(3));
int cid = location.getCid();
int lac = location.getLac();
cell.MCC = mcc;
cell.MNC = mnc;
cell.LAC = lac;
cell.CID = cid;
} else {
cell = null;
}
}
} else if (IMSI.startsWith("46003")) {
cell.NETWORK_TYPE = "CHINA TELECOM";
CdmaCellLocation location = (CdmaCellLocation) tm
.getCellLocation();
if (location == null) {
cell = null;
} else {
String operator = tm.getNetworkOperator();
if (operator.length() > 4) {
int mcc = Integer.parseInt(operator.substring(0, 3));
int mnc = Integer.parseInt(operator.substring(3));
int cid = location.getBaseStationId();
int lac = location.getNetworkId();
cell.MCC = mcc;
cell.MNC = mnc;
cell.LAC = lac;
cell.CID = cid;
} else {
cell = null;
}
}
} else {
// cell.NETWORK_TYPE = "UNDENTIFIED";
cell = null;
}
} else {
cell = null;
}
return cell;
}
/**
* 基站信息
*/
class SCell {
public String NETWORK_TYPE;
public int MCC;
public int MNC;
public int LAC;
public int CID;
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("network_type", NETWORK_TYPE);
json.put("mcc", MCC);
json.put("MNC", MNC);
json.put("LAC", LAC);
json.put("CID", CID);
return json;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
android获取包版本,Android获取应用名称、版本号、应用包名称,移动设备ID、MAC地址、基站信息和手机型号等详细信...相关推荐
- android arp工具,GitHub - SummerSnow274/ARP_sed_rev: 在Android通过ARP询问实现获取同一网络所有设备的MAC地址,AP隔离的网络除外...
ARP_sed_rev 在Android通过ARP询问实现获取同一网络所有设备的MAC地址,AP隔离的网络除外 arpsed.c 编译:gcc arpsed.c -o arpsed 运行:sudo . ...
- android 获取网卡mac_Java获取Linux安卓设备的mac地址方法
Java如何获取Linux或安卓Android设备的mac地址呢?方法非常简单,只需要使用下方代码即可轻松通过java获取mac地址了,代码如下:public String getMacAddress ...
- android 获取设备的mac地址,Android编程获取设备MAC地址的实现方法
本文实例讲述了Android编程获取设备MAC地址的实现方法.分享给大家供大家参考,具体如下: /** * 获取设备的mac地址 * * @param ac * @param callback * 成 ...
- android 获取mac c语言,获取设备的mac地址和IP地址(android6.0以上专用)
/** * 获取设备HardwareAddress地址 * @return */ public static String getMachineHardwareAddress(){ Enumerati ...
- Android studio 获取设备的Mac地址,wifi和以太网均可使用
/*** 获取设备的Mac地址* @return Mac地址*/public static String getLocalMacAddress() {String Mac=null;try{Strin ...
- 关于获取安卓设备的mac地址
今日发现一个问题,系统要求从设备上获取一个唯一码作为当前登录用户的唯一标识: 之前尝试过很多方法,最后决定采用mac地址. 官方获取mac地址的方法是: public static String ge ...
- 利用ioctl获取本机指定设备的MAC地址
// 利用ioctl获取本机指定设备的MAC地址 #include<stdio.h> #include<string.h> #include<stdlib.h> # ...
- Python获取电脑硬件配置的封装类,可以获取CPU序列号、主板序列号、BIOS序列号、硬盘序列号和网卡MAC地址
Python获取电脑硬件配置的封装类,可以获取CPU序列号.主板序列号.BIOS序列号.硬盘序列号和网卡MAC地址. myPyHardware.py # -*- coding: utf-8 -*- i ...
- android获取安卓版本,Android开发:获取安卓App版本号的方法步骤
今天国庆节,在这举国欢庆的日子里,发一篇博文留念一下这个特殊的日子,国庆依然奋战在工作一线. 在Android开发过程中,想要开发一个完整功能的App,各个地方的内容都要涉及到,比如获取App的系统版 ...
最新文章
- VNX证书过期解决方案(2018-11-02)
- python的pip安装-pip安装python库的方法总结
- 分布式事务中间件Fescar—全局写排它锁解读
- java中treemap_Java中TreeMap集合讲解
- 谷歌浏览器如何将繁体字设置成中文?
- (转) Twisted :第十九部分 改变之前的想法
- mysql workbench for ubuntu测试
- 程序员月入2万与5千,这就是差距!
- 2018北京ICPC D. Frog and Portal(构造)
- python写斗地主游戏_基于python的简单斗地主实现-Go语言中文社区
- sku mysql_MySQL-THINKPHP 商城系统二 商品模块的展示
- 鼠标悬停在HTML-TABLE的某一行上 改变这一行的背景颜色
- linux安装水星网卡驱动,centos7.5 安装无线网卡驱动
- Android版疯狂填字第三关,iOS/安卓版《疯狂填字3》答案攻略第140关
- Push to branch was rejected
- 几种常用的操作系统调度策略
- 软件测试整理:测试设计
- Echarts实现以秒为单位的动态三条折线图显示
- Managed Beans
- duilib库combo box提供输入字符模糊查询
热门文章
- 【原创】开源,手中的牌怎么打
- VMware共享文件夹
- java set排序_Java Set元素 排序
- android:关于字体问题
- TCP 的演化史-byte stream 和 packet
- Istio 正式成为 CNCF 孵化项目,F-16 战斗机早部署上了?
- Linux 下socket编程 connect()函数返回-1(error:Connection refused)
- 微信/QQ/TIM防撤回神器,看见没有,这就是撤回狗
- Ubuntu20.04静态IP设置
- python实现lfm_推荐系统-基于矩阵分解的LFM模型