Android-获取手机信息

public class DeviceInfo {

	/**
	 * MAC address of the device which will be used while communicating with the
	 * server
	 */
	private static String _localId = null;

	/**
	 * Method to get the local Id as the MAC address of the phone.
	 */
	public static void initLocalId() {
		WifiManager wifiManager = (WifiManager) CppApplication.getAppContext()
				.getSystemService(Context.WIFI_SERVICE);
		WifiInfo wInfo = wifiManager.getConnectionInfo();
		_localId = wInfo.getMacAddress();
		VCLog.info(Category.CAT_GENERAL, "DeviceInfo: initLocalId: wifiSsid->"
				+ _localId);
	}

	/***
	 * Get MAC address of device
	 * 
	 * @return MAC address
	 */
	public static String getLocalID() {
		if (_localId == null) {
			initLocalId();
		}
		return _localId;
	}

	/**
	 * Method to get the device model. e.g. Droid 3
	 * 
	 * @return The model name of the device.
	 */
	public String getDeviceModel() {
		String model = Build.MODEL;
		return model;
	}

	/**
	 * This method is used to get the manufacturer.
	 * 
	 * @return the manufacturer.
	 */
	public String getDeviceManufacturer() {
		String manufacturer = Build.MANUFACTURER;
		return manufacturer;

	}

	public static String getDataShaHashed(String str) {
		MessageDigest digest = null;
		byte[] input = null;

		try {
			digest = MessageDigest.getInstance("SHA-1");
			digest.reset();
			input = digest.digest(str.getBytes("UTF-8"));

		} catch (Exception e) {
			VCLog.error(
					Category.CAT_GENERAL,
					"DeviceInfo: getDataShaHashed: Exception->"
							+ e.getMessage());
		}
		return _convertToHex(input);
	}

	private static String _convertToHex(byte[] data) {
		StringBuffer buf = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			int halfbyte = (data[i] >>> 4) & 0x0F;
			int two_halfs = 0;
			do {
				if ((0 <= halfbyte) && (halfbyte <= 9))
					buf.append((char) ('0' + halfbyte));
				else
					buf.append((char) ('a' + (halfbyte - 10)));
				halfbyte = data[i] & 0x0F;
			} while (two_halfs++ < 1);
		}
		return buf.toString();
	}

	public static String getCurrentTimeStamp() {
		SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date now = new Date();
		String strDate = sdfDate.format(now);
		strDate = strDate.replace(" ", "T");
		return strDate;
	}

	/**
	 * This function returns unique device id i.e. IMEI number for current
	 * device returns null if not able to find device id
	 * 
	 * @return String containing Device id, null if not able to find
	 * */
	public static String getDeviceId() {
		TelephonyManager telephonyManager = (TelephonyManager) CppApplication
				.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
		String deviceId = null;
		if (telephonyManager != null) {
			deviceId = telephonyManager.getDeviceId();
			telephonyManager = null;
		}
		return deviceId;
	}

	/**
	 * This function checks whether SD card is present or not and whether space
	 * is available or not.
	 * 
	 * @return true if SD card is available, false otherwise.
	 */
	public static boolean isSdCardPresent() {

		String sdCardStatus = android.os.Environment.getExternalStorageState();
		boolean isSdCardAvailable = sdCardStatus
				.equals(android.os.Environment.MEDIA_MOUNTED);
		return isSdCardAvailable;
	}

	public static String getSdCardPath() {
		File externalStorage = Environment.getExternalStorageDirectory();
		String sdcardPath = externalStorage.getAbsolutePath();
		return sdcardPath;
	}

	/**
	 * This method is used to get the OS version.
	 * 
	 * @return the OS version.
	 */
	public static int getDeviceOsVersion() {
		int ver = Build.VERSION.SDK_INT;
		return ver;
	}

	public static String getLocale() {
		return CppApplication.getAppContext().getResources().getConfiguration().locale
				.getDisplayCountry(Locale.getDefault());
	}
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值