android 开发技巧--1
上一篇 /
下一篇 2013-02-04 16:46:57
/ 个人分类:android开发
一:
获取程序的版本号,用于提示用户更新
public static int getApplicationVersionCode(Context context) {
int result = -1;
try {
PackageManager manager = context.getPackageManager();
PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0)
result = info.versionCode;
} catch (NameNotFoundException e) {
Log.w("ApplicationUtils", "Unable to get application version: " + e.getMessage());
result = -1;
}
return result;
}
二:
检测SD卡状态
public static boolean checkCardState(Context context, boolean showMessage) {
// Check to see if we have an SDCard
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED)) {
int messageId;
// Check to see if the SDCard is busy, same as the music app
if (status.equals(Environment.MEDIA_SHARED)) {
messageId = R.string.Commons_SDCardErrorSDUnavailable;
} else {
messageId = R.string.Commons_SDCardErrorNoSDMsg;
}
if (showMessage) {
ApplicationUtils.showErrorDialog(context, R.string.Commons_SDCardErrorTitle, messageId);
}
return false;
}
return true;
}
三:
收藏
举报
TAG: