Last active
July 23, 2017 04:56
-
-
Save D-clock/26f50a4c7f9dbefffb9e4543b1dd3c1b to your computer and use it in GitHub Desktop.
Android系统实用工具类
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.content.pm.PackageInfo; | |
import android.content.pm.PackageManager; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
import android.os.Environment; | |
import android.provider.Settings; | |
import android.telephony.TelephonyManager; | |
import android.text.TextUtils; | |
/** | |
* 系统实用工具类 | |
* <p/> | |
* Created by Clock on 2016/1/24. | |
*/ | |
public class SystemUtils { | |
private SystemUtils(){ | |
} | |
/** | |
* 获取设备的制造商 | |
* | |
* @return 设备制造商 | |
*/ | |
public static String getDeviceManufacture() { | |
return android.os.Build.MANUFACTURER; | |
} | |
/** | |
* 获取设备名称 | |
* | |
* @return 设备名称 | |
*/ | |
public static String getDeviceName() { | |
return android.os.Build.MODEL; | |
} | |
/** | |
* 获取系统版本号 | |
* | |
* @return 系统版本号 | |
*/ | |
public static String getSystemVersion() { | |
return android.os.Build.VERSION.RELEASE; | |
} | |
/** | |
* 获取设备号 | |
* | |
* @param context | |
* @return | |
*/ | |
public static String getDeviceIMEI(Context context) { | |
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
if (telephonyManager == null || TextUtils.isEmpty(telephonyManager.getDeviceId())) { | |
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); | |
} else { | |
return telephonyManager.getDeviceId(); | |
} | |
} | |
/** | |
* 获取应用的版本号 | |
* | |
* @param context | |
* @return | |
*/ | |
public static String getAppVersion(Context context) { | |
PackageManager packageManager = context.getPackageManager(); | |
PackageInfo packageInfo; | |
try { | |
packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); | |
return packageInfo.versionName; | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
/** | |
* 判断当前有没有网络连接 | |
* | |
* @param context | |
* @return | |
*/ | |
public static boolean getNetworkState(Context context) { | |
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo networkinfo = manager.getActiveNetworkInfo(); | |
if (networkinfo == null || !networkinfo.isAvailable()) { | |
return false; | |
} | |
return true; | |
} | |
/** | |
* SD卡是否挂载 | |
* | |
* @return | |
*/ | |
public static boolean mountedSdCard() { | |
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment