信息android开发中apk安装包常用工具

android开发工具  时间:2021-02-28  阅读:()

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;

BuyVM新设立的迈阿密机房速度怎么样?简单的测评速度性能

BuyVM商家算是一家比较老牌的海外主机商,公司设立在加拿大,曾经是低价便宜VPS主机的代表,目前为止有提供纽约、拉斯维加斯、卢森堡机房,以及新增加的美国迈阿密机房。如果我们有需要选择BuyVM商家的机器需要注意的是注册信息的时候一定要规范,否则很容易出现欺诈订单,甚至你开通后都有可能被禁止账户,也是这个原因,曾经被很多人吐槽的。这里我们简单的对于BuyVM商家新增加的迈阿密机房进行简单的测评。如...

ZJI(月付480元),香港阿里云专线服务器

ZJI是成立于2011年原Wordpress圈知名主机商—维翔主机,2018年9月更名为ZJI,主要提供香港、日本、美国独立服务器(自营/数据中心直营)租用及VDS、虚拟主机空间、域名注册业务。本月商家针对香港阿里云线路独立服务器提供月付立减270-400元优惠码,优惠后香港独立服务器(阿里云专线)E3或者E5 CPU,SSD硬盘,最低每月仅480元起。阿里一型CPU:Intel E5-2630L...

tmhhost(100元/季)自带windows系统,香港(三网)cn2 gia、日本cn2、韩国cn2、美国(三网)cn2 gia、美国cn2gia200G高防

tmhhost可谓是相当熟悉国内网络情况(资质方面:ISP\ICP\工商齐备),专业售卖海外高端优质线路的云服务器和独立服务器,包括了:香港的三网cn2 gia、日本 cn2、日本软银云服务器、韩国CN2、美国三网cn2 gia 云服务器、美国 cn2 gia +200G高防的。另外还有国内云服务器:镇江BGP 大连BGP数据盘和系统盘分开,自带windows系统,支持支付宝付款和微信,简直就是专...

android开发工具为你推荐
在线漏洞检测如果检测网站是否有漏洞?渗透测试软件测试与渗透测试那个工作有前途二叉树遍历二叉树三种遍历方式原则?网站联盟百度网盟是什么,怎么加入申请证书一、如何申请证书?畅想中国淄博畅想中国消费怎么样qq空间打扮QQ空间打扮人人逛街包公免费逛街打一成语idc前线穿越火线河北的服务器好卡 有人知道怎么回事嘛 知道的速回mate8价格华为麦特八多少价格
中国域名网 注册cn域名 主机优惠码 狗爹 tightvnc 小米数据库 股票老左 服务器硬件防火墙 根服务器 cloudlink 1元域名 登陆空间 帽子云排名 工信部网站备案查询 国内空间 .htaccess cdn加速技术 cc加速器 海尔t68驱动 免费php空间申请 更多