获取App应用版本信息工具类

来源:互联网 发布:ip反查域名网站 编辑:程序博客网 时间:2024/06/08 13:16


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.android.net.RequestParams;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;;

/**

 * 主要功能:获取App应用版本信息

 *@author caijin

 */
@SuppressWarnings("rawtypes")
public class ApplicationAppMgr {


/**
* 获取本地Apk版本号
* @param context 上下文
* @return int   
*/
public static int getVerCode(Context context) {
int verCode = -1;
try {
verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
AppLogMessageMgr.e("ApplicationAppMgr-->>getVerCode()", e.getMessage() + "获取本地Apk版本号失败!");
e.printStackTrace();
}
return verCode;
}


/**
* 获取本地Apk版本名称
* @param context 上下文
* @return String   
*/
public static String getVerName(Context context) {
String verName = "";
try {
verName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
AppLogMessageMgr.e("ApplicationAppMgr-->>getVerName()", e.getMessage() + "获取本地Apk版本名称失败!");
e.printStackTrace();
}
return verName;
}


/**
* 获得当前版本信息
* @param keyValues key信息
* @return RequestParams   
*/
public static RequestParams getRequestParams(HashMap<String,String> keyValues){
RequestParams params = new RequestParams();
Iterator iterator = keyValues.entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            params.put((String) key, entry.getValue().toString());
        }
return params;
}

}

最后附上所有工具类的下载链接:

http://download.csdn.net/detail/u014727709/9697759


转载自:http://blog.csdn.net/u014727709/article/details/53390098

欢迎start,欢迎评论,欢迎指正

0 0
原创粉丝点击