安卓手机相关工具类,很全很有用,50w字+的Android技术类校招面试题汇总

if (!TextUtils.isEmpty(_AndroidID)) {

return _AndroidID;

}else {

return getIMEI();

}

} catch (Exception e) {

e.printStackTrace();

}

return _AndroidID;

}

/**

  • 获取APP版本号

  • @param context

  • @return AppVersionName

*/

public static String getAppVersionName() {

String versionName = “”;

try {

PackageManager pm = NewsApplication.sAppContext.getPackageManager();

PackageInfo pi = pm.getPackageInfo(NewsApplication.sAppContext.getPackageName(), 0);

versionName = pi.versionName;

if (versionName == null || versionName.length() <= 0) {

return “”;

}

} catch (Exception e) {

Log.e(“VersionInfo”, “Exception”, e);

}

return versionName;

}

/**

  • 获取APP版本号

  • @param context

  • @return AppVersionCode

*/

public static int getAppVersionCode() {

int versionCode = 0;

try {

PackageManager pm = NewsApplication.sAppContext.getPackageManager();

PackageInfo pi = pm.getPackageInfo(NewsApplication.sAppContext.getPackageName(), 0);

versionCode = pi.versionCode;

} catch (Exception e) {

Log.e(“VersionInfo”, “Exception”, e);

}

return versionCode;

}

/**

  • IMEI号,唯一的数字,标识了 GSM 和 UMTS网络里的唯一一个手机

  • DeviceId

  • @return

*/

public static String getIMEI() {

return ((TelephonyManager) NewsApplication.sAppContext.getSystemService(Context.TELEPHONY_SERVICE))

.getDeviceId();

}

/**

  • IESI号,唯一的数字,标识了GSM和UMTS 网络里的唯一一个用户

  • @return

*/

public static String getIMSI() {

return ((TelephonyManager) NewsApplication.sAppContext.getSystemService(Context.TELEPHONY_SERVICE))

.getSubscriberId();

}

//获取MCC、MNC

static GetMCCAndMNC mGetMCCAndMNC;

public interface GetMCCAndMNC {

public void onSuccess(String pMCC, String pMNC);

public void onFailure();

}

/**

  • 获取MCC、MNC

  • @param pContext

  • @param pMCCAndMNC new GetMCCAndMNC(){};

*/

public static void getMCCAndMNC(Context pContext,GetMCCAndMNC pMCCAndMNC) {

mGetMCCAndMNC = pMCCAndMNC;

String _networkOperator = ((TelephonyManager) pContext.getSystemService(Context.TELEPHONY_SERVICE)).getNetworkOperator();

if (TextUtils.isEmpty(_networkOperator)) {

mGetMCCAndMNC.onFailure();

}else {

if (_networkOperator.length() < 5) {

mGetMCCAndMNC.onFailure();

}else {

String _MCC =_networkOperator.substring(0, 3);

String _MNC = _networkOperator.substring(3);

if (!TextUtils.isEmpty(_MCC) && !TextUtils.isEmpty(_MNC)) {

mGetMCCAndMNC.onSuccess(_MCC, _MNC);

}else{

mGetMCCAndMNC.onFailure();

}

}

}

}

/**

  • 手机品牌

  • @return

*/

public static String getBrand() {

return android.os.Build.BRAND;

}

/**

  • 手机型号

  • @return

*/

public static String getMobileModel() {

return android.os.Build.MODEL;

}

/**

  • 手机号码

  • @return

*/

public static String getMobileNumber() {

return ((TelephonyManager) NewsApplication.sAppContext.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();

}

/**

  • SDK版本

  • @return

*/

public static int getSDKVersionNumber() {

return Build.VERSION.SDK_INT;

}

/**

  • 系统版本号

  • @return

*/

public static String getFrimWareVersionNumber() {

return Build.VERSION.RELEASE;

}

/**

  • 获取手机CPU核心数

  • @return

*/

public static int getNumCores()

{

// Private Class to display only CPU devices in the directory listing

class CpuFilter implements FileFilter

{

@Override

public boolean accept(File pathname)

{

// Check if filename is “cpu”, followed by a single digit number

if (Pattern.matches(“cpu[0-9]”, pathname.getName()))

{

return true;

}

return false;

}

}

try

{

// Get directory containing CPU info

File dir = new File("/sys/devices/system/cpu/");

// Filter to only list the devices we care about

File[] files = dir.listFiles(new CpuFilter());

// Return the number of cores (virtual CPU devices)

return files.length;

}

catch (Exception e)

{

e.printStackTrace();

// Default to return 1 core

return 1;

}

}

/**

  • 获得SDCard总大小

  • @return size (long)

*/

@SuppressWarnings(“deprecation”)

public static long getSDTotalSize() {

if (DeviceInfoUtils.hasSdcard()) {

File _FileExternalStorage = Environment.getExternalStorageDirectory();

StatFs _StatFs = new StatFs(_FileExternalStorage.getPath());

long _BlockSize, _TotalBlocks;

_BlockSize = _StatFs.getBlockSize();

_TotalBlocks = _StatFs.getBlockCount();

return _BlockSize * _TotalBlocks;

}else {

return 0;

}

}

/**

  • 获得SDCard剩余容量(可用大小 )

  • @return size (long)

*/

@SuppressWarnings(“deprecation”)

public static long getSDAvailableSize() {

if (DeviceInfoUtils.hasSdcard()) {

File _FileExternalStorage = Environment.getExternalStorageDirectory();

StatFs _StatFs = new StatFs(_FileExternalStorage.getPath());

long _BlockSize, _AvailableBlocks;

_BlockSize = _StatFs.getBlockSize();

_AvailableBlocks = _StatFs.getAvailableBlocks();

return _BlockSize * _AvailableBlocks;

}else {

return 0;

}

}

/**

  • 获得机身内存总大小

  • @return size (long)

*/

@SuppressWarnings(“deprecation”)

public long getRomTotalSize() {

File _FileDataDirectory = Environment.getDataDirectory();

StatFs _StatFs = new StatFs(_FileDataDirectory.getPath());

long _BlockSize, _TotalBlocks;

_BlockSize = _StatFs.getBlockSize();

_TotalBlocks = _StatFs.getBlockCount();

return _BlockSize * _TotalBlocks;

}

/**

  • 获得机身可用内存

  • @return size (long)

*/

@SuppressWarnings(“deprecation”)

public static long getRomAvailableSize() {

File _FileDataDirectory = Environment.getDataDirectory();

StatFs _StatFs = new StatFs(_FileDataDirectory.getPath());

long _BlockSize, _Avai
lableBlocks;

_BlockSize = _StatFs.getBlockSize();

_AvailableBlocks = _StatFs.getAvailableBlocks();

return _BlockSize * _AvailableBlocks;

}

/**

  • 获取手机MAC地址

  • @param pContext

  • @return

*/

public static String getMacAddress(Context pContext){

String result = “”;

WifiManager wifiManager = (WifiManager) pContext.getSystemService(Context.WIFI_SERVICE);

WifiInfo wifiInfo = wifiManager.getConnectionInfo();

result = wifiInfo.getMacAddress();

return result;

}

ze = _StatFs.getBlockSize();

_AvailableBlocks = _StatFs.getAvailableBlocks();

return _BlockSize * _AvailableBlocks;

}

/**

  • 获取手机MAC地址

  • @param pContext

  • @return

*/

public static String getMacAddress(Context pContext){

String result = “”;

WifiManager wifiManager = (WifiManager) pContext.getSystemService(Context.WIFI_SERVICE);

WifiInfo wifiInfo = wifiManager.getConnectionInfo();

result = wifiInfo.getMacAddress();

return result;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值