zoukankan      html  css  js  c++  java
  • android点滴(6)之获取Android系统中所有的开机自启动项

    获取Android系统中所有的开机自启动项

     

    绿水本无忧,因风皱面;青山原不老,为雪白头。

     

    思路:

    a.获取系统中安装的所有的应用程序的信息(ApplicationInfo)

    b.检查应用程序的Permission中是否有RECEIVE_BOOT_COMPLETED

     

    需要使用PackageManagerApplicationInfo类,

    PM类的文档如下:

                Class for retrieving various kinds of information related to the application packages that are currently installed on the device. You can find this class through getPackageManager().

                    中文:PM类可以用来获取安装在设备上的应用程序包相关的各种信息。可以通过getPackageManager()获取对象。

    ApplicationInfo类的文档如下:

                Information you can retrieve about a particular application. This corresponds to information collected from the AndroidManifest.xml's <application> tag.

                    中文:使用ApplicationInfo类你可以返回关于一个特定的应用程序的信息。这些信息是从AndroidManifest.xml<application>标签收集来的。

     

    例子:

     

    public class BootAppEnumUtils {

     

          private Context mContext;

          private static final String permName = "android.permission.RECEIVE_BOOT_COMPLETED";

          public BootAppEnumUtils(Context context){

                this.mContext = context;

          }

         

          public List<String> listBootApps(){

                List<String> bootAppNames = new ArrayList<String>();

                PackageManager pm = mContext.getPackageManager();

                //获取所有安装的App的信息

                List<ApplicationInfo> appInfos = pm.getInstalledApplications       (PackageManager.GET_UNINSTALLED_PACKAGES);

                for(ApplicationInfo appInfo : appInfos){

                      int iBoot = pm.checkPermission(permName, appInfo.packageName);

                      if(iBoot == PackageManager.PERMISSION_GRANTED ){

                            String appName = pm.getApplicationLabel(appInfo).toString();

                            bootAppNames.add(appName);

                      }

                }

                return bootAppNames;

          }

    }

     

    狂奔的蝸牛

    9/29/2011

     

     

  • 相关阅读:
    校验相关问题
    类型转换和操作符重载 (c#)
    泛型委托Func<string,string>()
    第三次作业 刘惠惠
    刘惠惠1.12
    第二次作业刘惠惠2.6,2.15
    刘惠惠1.8
    第四次作业 刘惠惠
    刘惠惠1.2
    设计模式中的单件模式
  • 原文地址:https://www.cnblogs.com/cody1988/p/2195701.html
Copyright © 2011-2022 走看看