Android开发中apk安装包常用工具
开发项目中用到的有关获取apk信息的工具类在做版本升级的时候一般都需要用到部分方法做点笔记public class AppUtil {
*根据应用包名package name启动应用
*参数分别是上下文c ontext和应用包名 pkgNamepublic static boolean startApkByPkgName(Context context,String pkgName) {
P ac kageManager pac kageManager=c ontext.getP ac kageManager();
Intent intent=new Intent();intent=pac kageManager.getLaunc hIntentF orP ac kage(pkgName);if(intent==null) {
System.out.println(APP not found!r eturn fals e;c ontext.startAc tivity(intent);return true;
*根据apk文件路径得到app信息public static ApplicationInfo getApkInfoByPath(Context context,String absPath) {
ApplicationInfo appInfo=null;
Pac kageManager pm=c ontext.getPac kageManager();
PackageInfo pkgInfo =pm.getPac kageArchiveInfo(absPath,Pac kageManager.GET_ACTI VITIES);if(pkgInfo!=null) {appInfo=pkgInfo.applic ationInfo;
/*必须加这两句不然下面icon获取是default icon而不是应用包的icon*/
appInfo.s ourc eDir=absPath;appInfo.public Sourc eDir=absPath;return appInfo;
*根据apk应用包名得到应用信息public static PackageInfo getApkInfoByPkgName(Context context,String pkgName) {PackageInfo pkgInfo=null;
Pac kageManager pm=c ontext.getPac kageManager();try{
//0代表是获取版本信息pkgInfo=pm.getPac kageInfo(pkgName,0);
} c atch(NameNotFoundExc eption e) {
//TODO Auto-generated catch blocke.printStackTrac e();return pkgInfo;
*根据apk文件路径得到应用信息public static PackageInfo getPkgInfoByPath(Context c ontext,String absPath) {PackageInfo pkgInfo=null;
Pac kageManager pm=c ontext.getPac kageManager();pkgInfo=pm.getPackageArchiveInfo(absPath,
Pac kageManager.GET_ACTI VITIES);return pkgInfo;
*根据apk路径直接跳到安装界面
public static void installApkByPath(Context context,String absPath) {
Intent intent=new Intent(Intent.ACTION_VIEW);intent.s etDataAndType(Uri.pars e(file://+abs Path),applic ation/vnd.android.package-archiveintent.s etFlags(Intent.FLAG_ACTIVITY_NEW_TAS K);c ontext.startAc tivity(intent);
*根据apk包名卸载应用public static void uninstallApk(Context context,String packageName) {
String uriString=package:+pac kageName;
Uri uninstallUrl=Uri.parse(uriString);
Intent intent=new Intent(Intent.ACTION_DELET E,uninstallUrl);c ontext.startAc tivity(intent);public static List ResolveInfo queryAppInfo(Context c ontext,
String packageName) {
Pac kageManager pm=c ontext.getPac kageManager(); //获得Pac kageManager对象Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);mainIntent.addCategory(Intent.CAT EGO RY_LAUNC HER);mainIntent.s etP ac kage(pac kageName);
//通过查询获得所有ResolveInfo对象.
List ResolveInfo resolveInfos=pm.queryIntentActivities(mainIntent,
P ac kageManager.GET_INTENT_FILTERS);return resolveInfos;
*根据名名获取版本信息public static int getInstalledAppVersionCode(Context context,String pkgName) {int versionCode=-1;
PackageInfo pkgInfo=AppUtil.getPkgInfoByName(c ontext,pkgName);if(pkgInfo!=null) {versionCode=pkgInfo.versionCode;return versionCode;
HostKvm是一家成立于2013年的国外主机服务商,主要提供VPS主机,基于KVM架构,可选数据中心包括日本、新加坡、韩国、美国、俄罗斯、中国香港等多个地区机房,均为国内直连或优化线路,延迟较低,适合建站或者远程办公等。商家本月针对香港国际机房提供特别7折优惠码,其他机房全场8折,优惠后2G内存香港VPS每月5.95美元起,支持使用PayPal或者支付宝付款。下面以香港国际(HKGlobal)为...
酷番云怎么样?酷番云就不讲太多了,介绍过很多次,老牌商家完事,最近有不少小伙伴,一直问我台湾VPS,比较难找好的商家,台湾VPS本来就比较少,也介绍了不少商家,线路都不是很好,有些需求支持Windows是比较少的,这里我们就给大家测评下 酷番云的台湾VPS,支持多个版本Linux和Windows操作系统,提供了CN2线路,并且还是原生IP,更惊喜的是提供的是无限流量。有需求的可以试试。可以看到回程...
香港ctg云服务器香港ctg云服务器官网链接 点击进入妮妮云官网优惠活动 香港CTG云服务器地区CPU内存硬盘带宽IP价格购买地址香港1核1G20G3M5个19元/月点击购买香港2核2G30G5M10个40元/月点击购买香港2核2G40G5M20个450元/月点击购买香港4核4G50G6M30个80元/月点击购买香...