• android代码集锦


    调用root权限的应用:

     1     /**
     2      * 执行Command命令的函数
     3      * 
     4      * @param command  命令
     5      * @return 执行结果
     6      */
     7     public static boolean runRootCommand(String command) {
     8         Process process = null;
     9         DataOutputStream os = null;
    10         try {
    11             process = Runtime.getRuntime().exec("su");
    12             os = new DataOutputStream(process.getOutputStream());
    13             os.writeBytes(command + "
    ");
    14             os.writeBytes("exit
    ");
    15             os.flush();
    16             process.waitFor();
    17         } catch (Exception e) {
    18             Log.d(TAG, "the device is not rooted, error message: " + e.getMessage());
    19             return false;
    20         } finally {
    21             try {
    22                 if (os != null) {
    23                     os.close();
    24                 }
    25                 if (process != null) {
    26                     process.destroy();
    27                 }
    28             } catch (Exception e) {
    29                 e.printStackTrace();
    30             }
    31         }
    32         return true;
    33     }

     

    获取安装了所有APP的信息:

     1     class PInfo {
     2         private String appname = "";
     3         private String pname = "";
     4         private String versionName = "";
     5         private int versionCode = 0;
     6         private Drawable icon;
     7 
     8         private void prettyPrint() {
     9             Log.i("MainActivity", appname + "|	" + pname + "|	" + versionName + "|	" + versionCode + "|	");
    10         }
    11     }
    12 
    13     private void listPackages() {
    14         // false = no system packages
    15         ArrayList<PInfo> apps = getInstalledApps(false);
    16         final int max = apps.size();
    17         for (int i = 0; i < max; i++) {
    18             apps.get(i).prettyPrint();
    19         }
    20     }
    21 
    22     private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
    23         ArrayList<PInfo> res = new ArrayList<PInfo>();
    24         List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
    25         for (int i = 0; i < packs.size(); i++) {
    26             PackageInfo p = packs.get(i);
    27             if ((!getSysPackages) && (p.versionName == null)) {
    28                 continue;
    29             }
    30             PInfo newInfo = new PInfo();
    31             newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
    32             newInfo.pname = p.packageName;
    33             newInfo.versionName = p.versionName;
    34             newInfo.versionCode = p.versionCode;
    35             newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
    36             res.add(newInfo);
    37         }
    38         return res;
    39     }

    ==

  • 相关阅读:
    C++中合并两个排行榜的思路
    C++函数类型以及函数表实验
    C++获取两个值的差距比
    windows下的bash工具:winbash
    导入sql文件提示2006错误的解决办法
    C++延迟delete对象方案:采用unique_ptr托管欲删除的对象指针
    C++使用lower_bound快速查询分段配置
    sqlserver数据库操作
    判断 iframe 是否加载完成的完美方法
    SQL数据缓存依赖 [SqlServer | Cache | SqlCacheDependency ]
  • 原文地址:https://www.cnblogs.com/zhjsll/p/5148505.html
Copyright © 2020-2023  润新知