/**
* 返回當前程序版本名
*/
public static String getAppVersionName(Context context) {
String versionName = "";
try {
// ---get the package info---
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
versionName = pi.versionName;
if (versionName == null || versionName.length() <= 0) {
return "";
}
} catch (Exception e) {
}
return versionName;
}
/*
* 判斷有沒有安裝某個應用程序
* */
public boolean checkApkExist(Context context, String packageName)
{
if (packageName == null || "".equals(packageName))
{
return false;
}
try
{
context.getPackageManager().getApplicationInfo(packageName,PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
}
catch (NameNotFoundException e)
{
return false;
}
}get
//sdcard是否可讀寫
public boolean IsCanUseSdCard() {
try {
return Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
//sim卡是否可讀
public boolean isCanUseSim() {
try {
TelephonyManager mgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return TelephonyManager.SIM_STATE_READY == mgr
.getSimState();
} catch (Exception e) {
e.printStackTrace();
}
return false;
} io