关闭

Android中操作App的一些常用方法

标签: appAndroid
92人阅读 评论(1) 收藏 举报
分类:

1.判断App是否安装

private boolean isAppInstalled(Context context, String uri) {
        PackageManager pm = context.getPackageManager();
        boolean installed = false;
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            installed = true;
        } catch (PackageManager.NameNotFoundException e) {
            installed = false;
        }
        return installed;
    }

2. public boolean isAppInstalled(Context context, String packageName) {
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        List<String> pName = new ArrayList<String>();
        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                pName.add(pn);
            }
        }
        return pName.contains(packageName);
    }

例子:

if (isInstallApp(MainActivity.this, "com.xxx")) {
                    System.out.println("Installed!!");
                } else {
                    System.out.println("Not installed!!");
                }
                

2.App请求root权限

  Process process = null;
        DataOutputStream os = null;
        try {
            String cmd = "chmod 777 " + getPackageCodePath();
            process = Runtime.getRuntime().exec("su"); // 切换到root帐号
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(cmd + "\n");
            os.writeBytes("exit\n");
            os.flush();
            process.waitFor();
        } catch (Exception e) {
            // return false;
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }

3.App实现静默安装



http://blog.csdn.net/h3c4lenovo/article/details/9202323

4.查看apk信息,keystore或者jks信息

1、查看 keystore 
$ keytool -list -v -keystore debug.keystore
$ keytool -list -v -keystore debug.keystore 
Enter keystore password:
2、查看三方应用或是系统应用签名
打开待查看的apk,将其中META-INF文件夹解压出来,得到其中的CERT.RSA文件
$ keytool -printcert -file META-INF/CERT.RSA
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:510076次
    • 积分:8398
    • 等级:
    • 排名:第2521名
    • 原创:313篇
    • 转载:109篇
    • 译文:0篇
    • 评论:58条
    个人联系方式
    加入我的QQ群
    文章分类