Android近期任务列表 Recent Applicatoins 分析 + Android PackageManager

来源:互联网 发布:剑三唐门成女捏脸数据 编辑:程序博客网 时间:2024/05/17 05:13

转自 : http://www.cnblogs.com/coding-way/archive/2013/06/05/3118732.html

这里的近期任务列表就是长按Home键出来的那个Dialog,里面放着近期打开过的应用,当然3.0以上系统的多任务切换键也是。

这个Dialog的实现在Android源码的/frameworks/base/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java中。

接下来就对这个源码分析一下。

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. public class RecentApplicationsDialog extends Dialog implements OnClickListener {  
  2.     // Elements for debugging support  
  3. //  private static final String LOG_TAG = "RecentApplicationsDialog";  
  4.     private static final boolean DBG_FORCE_EMPTY_LIST = false;  
  5.   
  6.     static private StatusBarManager sStatusBar;  
  7.   
  8.     private static final int NUM_BUTTONS = 8;  
  9.     private static final int MAX_RECENT_TASKS = NUM_BUTTONS * 2;    // allow for some discards  
  10.   
  11.     final TextView[] mIcons = new TextView[NUM_BUTTONS];  
  12.     View mNoAppsText;  
  13.     IntentFilter mBroadcastIntentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);  
  14.   
  15.     class RecentTag {  
  16.         ActivityManager.RecentTaskInfo info;  
  17.         Intent intent;  
  18.     }  
  19.   
  20.     Handler mHandler = new Handler();  
  21.     Runnable mCleanup = new Runnable() {  
  22.         public void run() {  
  23.             // dump extra memory we're hanging on to  
  24.             for (TextView icon: mIcons) {  
  25.                 icon.setCompoundDrawables(nullnullnullnull);  
  26.                 icon.setTag(null);  
  27.             }  
  28.         }  
  29.     };  
  30.   
  31.     public RecentApplicationsDialog(Context context) {  
  32.         super(context, com.android.internal.R.style.Theme_Dialog_RecentApplications);  
  33.   
  34.     }  
  35.   
  36.     /** 
  37.      * We create the recent applications dialog just once, and it stays around (hidden) 
  38.      * until activated by the user. 
  39.      * 
  40.      * @see PhoneWindowManager#showRecentAppsDialog 
  41.      */  
  42.     @Override  
  43.     protected void onCreate(Bundle savedInstanceState) {  
  44.         super.onCreate(savedInstanceState);  
  45.   
  46.         Context context = getContext();  
  47.   
  48.         if (sStatusBar == null) {  
  49.             sStatusBar = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);  
  50.         }  
  51.   
  52.         Window window = getWindow();  
  53.         window.requestFeature(Window.FEATURE_NO_TITLE);  
  54.         window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);  
  55.         window.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,  
  56.                 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);  
  57.         window.setTitle("Recents");  
  58.   
  59.         setContentView(com.android.internal.R.layout.recent_apps_dialog);  
  60.   
  61.         final WindowManager.LayoutParams params = window.getAttributes();  
  62.         params.width = WindowManager.LayoutParams.MATCH_PARENT;  
  63.         params.height = WindowManager.LayoutParams.MATCH_PARENT;  
  64.         window.setAttributes(params);  
  65.         window.setFlags(0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);  
  66.   
  67.         //默认显示8个  
  68.         mIcons[0] = (TextView)findViewById(com.android.internal.R.id.button0);  
  69.         mIcons[1] = (TextView)findViewById(com.android.internal.R.id.button1);  
  70.         mIcons[2] = (TextView)findViewById(com.android.internal.R.id.button2);  
  71.         mIcons[3] = (TextView)findViewById(com.android.internal.R.id.button3);  
  72.         mIcons[4] = (TextView)findViewById(com.android.internal.R.id.button4);  
  73.         mIcons[5] = (TextView)findViewById(com.android.internal.R.id.button5);  
  74.         mIcons[6] = (TextView)findViewById(com.android.internal.R.id.button6);  
  75.         mIcons[7] = (TextView)findViewById(com.android.internal.R.id.button7);  
  76.         mNoAppsText = findViewById(com.android.internal.R.id.no_applications_message);  
  77.   
  78.         //关键在哪,你懂得...  
  79.         for (TextView b: mIcons) {  
  80.             b.setOnClickListener(this);  
  81.         }  
  82.     }  
  83.   
  84.     @Override  
  85.     public boolean onKeyDown(int keyCode, KeyEvent event) {  
  86.         if (keyCode == KeyEvent.KEYCODE_TAB) {  
  87.             // Ignore all meta keys other than SHIFT.  The app switch key could be a  
  88.             // fallback action chorded with ALT, META or even CTRL depending on the key map.  
  89.             // DPad navigation is handled by the ViewRoot elsewhere.  
  90.             final boolean backward = event.isShiftPressed();  
  91.             final int numIcons = mIcons.length;  
  92.             int numButtons = 0;  
  93.             while (numButtons < numIcons && mIcons[numButtons].getVisibility() == View.VISIBLE) {  
  94.                 numButtons += 1;  
  95.             }  
  96.             if (numButtons != 0) {  
  97.                 int nextFocus = backward ? numButtons - 1 : 0;  
  98.                 for (int i = 0; i < numButtons; i++) {  
  99.                     if (mIcons[i].hasFocus()) {  
  100.                         if (backward) {  
  101.                             nextFocus = (i + numButtons - 1) % numButtons;  
  102.                         } else {  
  103.                             nextFocus = (i + 1) % numButtons;  
  104.                         }  
  105.                         break;  
  106.                     }  
  107.                 }  
  108.                 final int direction = backward ? View.FOCUS_BACKWARD : View.FOCUS_FORWARD;  
  109.                 if (mIcons[nextFocus].requestFocus(direction)) {  
  110.                     mIcons[nextFocus].playSoundEffect(  
  111.                             SoundEffectConstants.getContantForFocusDirection(direction));  
  112.                 }  
  113.             }  
  114.   
  115.             // The dialog always handles the key to prevent the ViewRoot from  
  116.             // performing the default navigation itself.  
  117.             return true;  
  118.         }  
  119.   
  120.         return super.onKeyDown(keyCode, event);  
  121.     }  
  122.   
  123.     /** 
  124.      * Dismiss the dialog and switch to the selected application. 
  125.      */  
  126.     public void dismissAndSwitch() {  
  127.         final int numIcons = mIcons.length;  
  128.         RecentTag tag = null;  
  129.         for (int i = 0; i < numIcons; i++) {  
  130.             if (mIcons[i].getVisibility() != View.VISIBLE) {  
  131.                 break;  
  132.             }  
  133.             if (i == 0 || mIcons[i].hasFocus()) {  
  134.                 tag = (RecentTag) mIcons[i].getTag();  
  135.                 if (mIcons[i].hasFocus()) {  
  136.                     break;  
  137.                 }  
  138.             }  
  139.         }  
  140.         if (tag != null) {  
  141.             switchTo(tag);  
  142.         }  
  143.         dismiss();  
  144.     }  
  145.   
  146.     /** 
  147.      * Handler for user clicks.  If a button was clicked, launch the corresponding activity. 
  148.      */  
  149.     public void onClick(View v) {  
  150.         for (TextView b: mIcons) {  
  151.             if (b == v) {  
  152.                 RecentTag tag = (RecentTag)b.getTag();  
  153.                 switchTo(tag);  
  154.                 break;  
  155.             }  
  156.         }  
  157.         dismiss();  
  158.     }  
  159.   
  160.     //  
  161.     private void switchTo(RecentTag tag) {  
  162.         if (tag.info.id >= 0) {  
  163.             // This is an active task; it should just go to the foreground.  
  164.             final ActivityManager am = (ActivityManager)  
  165.                     getContext().getSystemService(Context.ACTIVITY_SERVICE);  
  166.             am.moveTaskToFront(tag.info.id, ActivityManager.MOVE_TASK_WITH_HOME);  
  167.         } else if (tag.intent != null) {  
  168.             tag.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY  
  169.                     | Intent.FLAG_ACTIVITY_TASK_ON_HOME);  
  170.             try {  
  171.                 getContext().startActivity(tag.intent);  
  172.             } catch (ActivityNotFoundException e) {  
  173.                 Log.w("Recent""Unable to launch recent task", e);  
  174.             }  
  175.         }  
  176.     }  
  177.   
  178.     /** 
  179.      * Set up and show the recent activities dialog. 
  180.      */  
  181.     @Override  
  182.     public void onStart() {  
  183.         super.onStart();  
  184.         reloadButtons();  
  185.         if (sStatusBar != null) {  
  186.             sStatusBar.disable(StatusBarManager.DISABLE_EXPAND);  
  187.         }  
  188.   
  189.         // receive broadcasts  
  190.         getContext().registerReceiver(mBroadcastReceiver, mBroadcastIntentFilter);  
  191.   
  192.         mHandler.removeCallbacks(mCleanup);  
  193.     }  
  194.   
  195.     /** 
  196.      * Dismiss the recent activities dialog. 
  197.      */  
  198.     @Override  
  199.     public void onStop() {  
  200.         super.onStop();  
  201.   
  202.         if (sStatusBar != null) {  
  203.             sStatusBar.disable(StatusBarManager.DISABLE_NONE);  
  204.         }  
  205.   
  206.         // stop receiving broadcasts  
  207.         getContext().unregisterReceiver(mBroadcastReceiver);  
  208.   
  209.         mHandler.postDelayed(mCleanup, 100);  
  210.      }  
  211.   
  212.     /** 
  213.      * Reload the 6 buttons with recent activities 
  214.      */  
  215.     private void reloadButtons() {  
  216.   
  217.         final Context context = getContext();  
  218.         final PackageManager pm = context.getPackageManager();  
  219.         final ActivityManager am = (ActivityManager)  
  220.                 context.getSystemService(Context.ACTIVITY_SERVICE);  
  221.         final List<ActivityManager.RecentTaskInfo> recentTasks =  
  222.                 am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);  
  223.   
  224.         ActivityInfo homeInfo =   
  225.             new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)  
  226.                     .resolveActivityInfo(pm, 0);  
  227.   
  228.         IconUtilities iconUtilities = new IconUtilities(getContext());  
  229.   
  230.         // Performance note:  Our android performance guide says to prefer Iterator when  
  231.         // using a List class, but because we know that getRecentTasks() always returns  
  232.         // an ArrayList<>, we'll use a simple index instead.  
  233.         int index = 0;  
  234.         int numTasks = recentTasks.size();  
  235.         for (int i = 0; i < numTasks && (index < NUM_BUTTONS); ++i) {  
  236.             final ActivityManager.RecentTaskInfo info = recentTasks.get(i);  
  237.   
  238.             // for debug purposes only, disallow first result to create empty lists  
  239.             if (DBG_FORCE_EMPTY_LIST && (i == 0)) continue;  
  240.   
  241.             Intent intent = new Intent(info.baseIntent);  
  242.             if (info.origActivity != null) {  
  243.                 intent.setComponent(info.origActivity);  
  244.             }  
  245.   
  246.             // Skip the current home activity.  
  247.             if (homeInfo != null) {  
  248.                 if (homeInfo.packageName.equals(  
  249.                         intent.getComponent().getPackageName())  
  250.                         && homeInfo.name.equals(  
  251.                                 intent.getComponent().getClassName())) {  
  252.                     continue;  
  253.                 }  
  254.             }  
  255.   
  256.             intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)  
  257.                     | Intent.FLAG_ACTIVITY_NEW_TASK);  
  258.             final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);  
  259.             if (resolveInfo != null) {  
  260.                 final ActivityInfo activityInfo = resolveInfo.activityInfo;  
  261.                 final String title = activityInfo.loadLabel(pm).toString();  
  262.                 Drawable icon = activityInfo.loadIcon(pm);  
  263.   
  264.                 if (title != null && title.length() > 0 && icon != null) {  
  265.                     final TextView tv = mIcons[index];  
  266.                     tv.setText(title);  
  267.                     icon = iconUtilities.createIconDrawable(icon);  
  268.                     tv.setCompoundDrawables(null, icon, nullnull);  
  269.                     RecentTag tag = new RecentTag();  
  270.                     tag.info = info;  
  271.                     tag.intent = intent;  
  272.                     tv.setTag(tag);  
  273.                     tv.setVisibility(View.VISIBLE);  
  274.                     tv.setPressed(false);  
  275.                     tv.clearFocus();  
  276.                     ++index;  
  277.                 }  
  278.             }  
  279.         }  
  280.   
  281.         // handle the case of "no icons to show"  
  282.         mNoAppsText.setVisibility((index == 0) ? View.VISIBLE : View.GONE);  
  283.   
  284.         // hide the rest  
  285.         for (; index < NUM_BUTTONS; ++index) {  
  286.             mIcons[index].setVisibility(View.GONE);  
  287.         }  
  288.     }  
  289.   
  290.     /** 
  291.      * This is the listener for the ACTION_CLOSE_SYSTEM_DIALOGS intent.  It's an indication that 
  292.      * we should close ourselves immediately, in order to allow a higher-priority UI to take over 
  293.      * (e.g. phone call received). 
  294.      */  
  295.     private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {  
  296.         @Override  
  297.         public void onReceive(Context context, Intent intent) {  
  298.             String action = intent.getAction();  
  299.             if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {  
  300.                 String reason = intent.getStringExtra(PhoneWindowManager.SYSTEM_DIALOG_REASON_KEY);  
  301.                 if (! PhoneWindowManager.SYSTEM_DIALOG_REASON_RECENT_APPS.equals(reason)) {  
  302.                     dismiss();  
  303.                 }  
  304.             }  
  305.         }  
  306.     };  
  307. }  
  308.   
  309. RecentApplicationsDialog.java完整源码  

从源码可以看出,关键部分有三处。

 

一个很关键的内部类:

// 每个任务都包含一个Tag,这个Tag保存着这个App的一些非常有用的信息    class RecentTag {        ActivityManager.RecentTaskInfo info;        Intent intent;    }

这个RecentTag保存在每个近期任务的图标里,并且保存着这个任务的原始信息。

 

刚启动Dialog时对每个任务的初始化:

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. private void reloadButtons() {  
  2.   
  3.         final Context context = getContext();  
  4.         final PackageManager pm = context.getPackageManager();  
  5.         final ActivityManager am = (ActivityManager)  
  6.                 context.getSystemService(Context.ACTIVITY_SERVICE);  
  7.                   
  8.         //拿到最近使用的应用的信息列表  
  9.         final List<ActivityManager.RecentTaskInfo> recentTasks =  
  10.                 am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);  
  11.   
  12.         //自制一个home activity info,用来区分  
  13.         ActivityInfo homeInfo =   
  14.             new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)  
  15.                     .resolveActivityInfo(pm, 0);  
  16.   
  17.         IconUtilities iconUtilities = new IconUtilities(getContext());  
  18.   
  19.         int index = 0;  
  20.         int numTasks = recentTasks.size();  
  21.         //开始初始化每个任务的信息  
  22.         for (int i = 0; i < numTasks && (index < NUM_BUTTONS); ++i) {  
  23.             final ActivityManager.RecentTaskInfo info = recentTasks.get(i);  
  24.   
  25.             //复制一个任务的原始Intent  
  26.             Intent intent = new Intent(info.baseIntent);  
  27.             if (info.origActivity != null) {  
  28.                 intent.setComponent(info.origActivity);  
  29.             }  
  30.   
  31.             //跳过home activity  
  32.             if (homeInfo != null) {  
  33.                 if (homeInfo.packageName.equals(  
  34.                         intent.getComponent().getPackageName())  
  35.                         && homeInfo.name.equals(  
  36.                                 intent.getComponent().getClassName())) {  
  37.                     continue;  
  38.                 }  
  39.             }  
  40.   
  41.             intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)  
  42.                     | Intent.FLAG_ACTIVITY_NEW_TASK);  
  43.             final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);  
  44.             if (resolveInfo != null) {  
  45.                 final ActivityInfo activityInfo = resolveInfo.activityInfo;  
  46.                 final String title = activityInfo.loadLabel(pm).toString();  
  47.                 Drawable icon = activityInfo.loadIcon(pm);  
  48.   
  49.                 if (title != null && title.length() > 0 && icon != null) {  
  50.                     final TextView tv = mIcons[index];  
  51.                     tv.setText(title);  
  52.                     icon = iconUtilities.createIconDrawable(icon);  
  53.                     tv.setCompoundDrawables(null, icon, nullnull);  
  54.                     //new一个Tag,保存这个任务的RecentTaskInfo和Intent  
  55.                     RecentTag tag = new RecentTag();  
  56.                     tag.info = info;  
  57.                     tag.intent = intent;  
  58.                     tv.setTag(tag);  
  59.                     tv.setVisibility(View.VISIBLE);  
  60.                     tv.setPressed(false);  
  61.                     tv.clearFocus();  
  62.                     ++index;  
  63.                 }  
  64.             }  
  65.         }  
  66.   
  67.        ...//无关紧要的代码  
  68.     }  

这里的过程是:先用ActivityManager获取RecentTasks并生成一个List,然后利用这个List为Dialog中的每个任务初始化,并生成对应的信息RecentTag。

需要注意的是,RecentTag中的Intent是从对应任务的原始Intent复制过来的,这意味着那个原始Intent的一些Extra参数将会一并复制过来,

我来举个例子:比如我的App支持从第三方启动,并且第三方要提供一个token,当然这个token就以Extra参数的形式放进Intent里,然后通过startActivity()启动我的App;然后我的App根据这个token来处理,注意这里,当我的App退出后,再从近期任务里启动这个App,之前的那个token还会传递给我的App,这里就会出现错误了,原因就是上面分析的。这就是为什么从第三方跳转的应用不会出现在近期任务的列表里(比如点击短信里的url启动一个浏览器,之后近期任务里只有短信app,不会出现浏览器app)。要想不出现在近期任务里,可以给Intent设置FLAG_ACTIVITY_NO_HISTORY标志。

 

响应每个任务的点击事件:

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. private void switchTo(RecentTag tag) {  
  2.         if (tag.info.id >= 0) {  
  3.             // 这个Task没有退出,直接移动到前台  
  4.             final ActivityManager am = (ActivityManager)  
  5.                     getContext().getSystemService(Context.ACTIVITY_SERVICE);  
  6.             am.moveTaskToFront(tag.info.id, ActivityManager.MOVE_TASK_WITH_HOME);  
  7.         } else if (tag.intent != null) {  
  8.             //task退出了的话,id为-1,则使用RecentTag中的Intent重新启动  
  9.             tag.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY  
  10.                     | Intent.FLAG_ACTIVITY_TASK_ON_HOME);  
  11.             try {  
  12.                 getContext().startActivity(tag.intent);  
  13.             } catch (ActivityNotFoundException e) {  
  14.                 Log.w("Recent""Unable to launch recent task", e);  
  15.             }  
  16.         }  
  17.     }  

如果该Task没有退出,只是切到后台,则切换到前台;如果已经退出,就要重新启动了。

这里的Intent就是之前说的,重复使用的旧Intent了,这里注意,系统添加了FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY和FLAG_ACTIVITY_TASK_ON_HOME标志,所以我们可以在App中通过判断Intent的flag是否包含这两个来判断是否是从近期任务里启动的。注意FLAG_ACTIVITY_TASK_ON_HOME标志是Api 11添加的,所以11一下的之判断FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY就行了。


============================================================================================================================

本节内容是如何获取Android系统中应用程序的信息,主要包括packagename、label、icon、占用大小等。具体分为两个 部分,计划如下:
第一部分: 获取应用程序的packagename、label、icon等 ;

第二部分: 获取应用程序的占用大小,包括:缓存大小(cachsize)、数据大小(datasize)。

每部分都为您准备了简单丰富的实例,您一定不会错过。

Android系统为我们提供了很多服务管理的类,包括ActivityManager、PowerManager(电源管理)、AudioManager(音频管理)

等。除此之外,还提供了一个PackageManger管理类,它的主要职责是管理应用程序包。 通过它,我们就可以获取应用程序信息。

引入: AnroidManifest.xml文件节点说明: 

相关类的介绍

PackageItemInfo类          说明: AndroidManifest.xml文件中所有节点的基类,提供了这些节点的基本信息:a label、icon、 meta-data。它并不     直接使用,而是由子类继承然后调用相应方法。          常用字段:               public int icon           获得该资源图片在R文件中的值 (对应于android:icon属性)               public int labelRes     获得该label在R文件中的值(对应于android:label属性)               public String name   获得该节点的name值 (对应于android:name属性)               public String packagename   获得该应用程序的包名 (对应于android:packagename属性)         常用方法:              Drawable  loadIcon(PackageManager pm)               获得当前应用程序的图像              CharSequence  loadLabel(PackageManager pm)     获得当前应用程序的label   ActivityInfo类  继承自 PackageItemInfo          说明: 获得应用程序中<activity/>或者 <receiver />节点的信息 。我们可以通过它来获取我们设置的任何属性,包括      theme 、launchMode、launchmode等             常用方法继承至PackageItemInfo类中的loadIcon()和loadLabel()    ServiceInfo 类          说明: 同ActivityInfo类似 ,同样继承自 PackageItemInfo,只不过它表示的是<service>节点信息。    ApplicationInfo类 继承自  PackageItemInfo         说明:获取一个特定引用程序中<application>节点的信息。         字段说明:      flags字段: FLAG_SYSTEM 系统应用程序                   FLAG_EXTERNAL_STORAGE 表示该应用安装在sdcard中         常用方法继承至PackageItemInfo类中的loadIcon()和loadLabel()   ResolveInfo类        说明:根据<intent>节点来获取其上一层目录的信息,通常是<activity>、<receiver>、<service>节点信息。       常用字段:             public  ActivityInfo  activityInfo     获取 ActivityInfo对象,即<activity>或<receiver >节点信息             public ServiceInfo   serviceInfo     获取 ServiceInfo对象,即<activity>节点信息       常用方法:             Drawable loadIcon(PackageManager pm)             获得当前应用程序的图像             CharSequence loadLabel(PackageManager pm)  获得当前应用程序的label  PackageInfo类       说明:手动获取AndroidManifest.xml文件的信息 。       常用字段:           public String    packageName                   包名           public ActivityInfo[]     activities                   所有<activity>节点信息           public ApplicationInfo applicationInfo       <application>节点信息,只有一个           public ActivityInfo[]    receivers                  所有<receiver>节点信息,多个           public ServiceInfo[]    services                  所有<service>节点信息 ,多个 PackageManger 类      说明: 获得已安装的应用程序信息 。可以通过getPackageManager()方法获得。      常用方法:          public abstract PackageManager  getPackageManager()                 功能:获得一个PackageManger对象         public abstrac  tDrawable    getApplicationIcon(StringpackageName)               参数: packageName 包名               功能:返回给定包名的图标,否则返回null        public abstract ApplicationInfo   getApplicationInfo(String packageName, int flags)                参数:packagename 包名                           flags 该ApplicationInfo是此flags标记,通常可以直接赋予常数0即可               功能:返回该ApplicationInfo对象           public abstract List<ApplicationInfo>  getInstalledApplications(int flags)               参数:flag为一般为GET_UNINSTALLED_PACKAGES,那么此时会返回所有ApplicationInfo。我们可以对ApplicationInfo                     的flags过滤,得到我们需要的。               功能:返回给定条件的所有PackageInfo           public abstract List<PackageInfo>  getInstalledPackages(int flags)              参数如上             功能:返回给定条件的所有PackageInfo        public abstractResolveInfo  resolveActivity(Intent intent, int flags)            参数:  intent 查寻条件,Activity所配置的action和category                          flags: MATCH_DEFAULT_ONLY    :Category必须带有CATEGORY_DEFAULT的Activity,才匹配                                      GET_INTENT_FILTERS         :匹配Intent条件即可                                                  GET_RESOLVED_FILTER    :匹配Intent条件即可            功能 :返回给定条件的ResolveInfo对象(本质上是Activity)        public abstract  List<ResolveInfo>  queryIntentActivities(Intent intent, int flags)            参数同上            功能 :返回给定条件的所有ResolveInfo对象(本质上是Activity),集合对象       public abstract ResolveInfo  resolveService(Intent intent, int flags)           参数同上           功能 :返回给定条件的ResolveInfo对象(本质上是Service)      public abstract List<ResolveInfo> queryIntentServices(Intent intent, int flags)          参数同上          功能 :返回给定条件的所有ResolveInfo对象(本质上是Service),集合对象




0 0