有意思的android应用需求

a,之前有个客户的需求特别怪,要求应用不在全部应用程序列表里显示,通过拨打指定的电话号码形式启动应用,开始的想发就是在manifest.xml里的第一个activity里不添加<action android:name="android.intent.action.MAIN" />    <category android:name="android.intent.category.LAUNCHER" />这两个intentfilter。发现在4.0以上的版本就会出现错误!4.0会认为你这个是不安全的信息,无法启动。后来在PackageManager里发现了setComponentEnabledSetting这个方法,可以达到效果!看代码吧!

              
              
              
              
  1. //隐藏效果
  2. PackageManager p = getPackageManager();
  3. p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

//重新显示效果

               
               
               
               
  1. PackageManager p = getPackageManager();
  2. p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

   
   
   
   

    转:http://blog.csdn.net/commonslok/article/details/8148810

    b,获得所有开机运行的应用

       1:  static final String BOOT_START_PERMISSION = "android.permission.RECEIVE_BOOT_COMPLETED";
       2:   
       3:      public List<Map<String,Object>> fetch_installed_apps(Context context)
       4:      {
       5:          List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(0);
       6:          List<Map<String, Object>>list = new ArrayList<Map<String,Object>>(packages.size());
       7:          Iterator<ApplicationInfo> appInfoIterator = packages.iterator();
       8:   
       9:          while(appInfoIterator.hasNext())
      10:          {
      11:              ApplicationInfo app = (ApplicationInfo) appInfoIterator.next();
      12:              // 查找安装的package是否有开机启动权限
      13:              if(PackageManager.PERMISSION_GRANTED == context.getPackageManager().checkPermission(BOOT_START_PERMISSION, app.packageName))
      14:              {
      15:                  String label = context.getPackageManager().getApplicationLabel(app).toString();
      16:                  Drawable appIcon = context.getPackageManager().getApplicationIcon(app);
      17:                  Map<String,Object> map = new HashMap<String,Object>();
      18:                  map.put("name", label);
      19:                  map.put("desc", app.packageName);
      20:                  map.put("img", appIcon);
      21:                  list.add(map);
      22:              }
      23:          }
      24:          return list;
      25:      }

    你可能感兴趣的:(有意思的android应用需求)