在ActivityManager 中 有一个publish的函数为:getRecentTasksThe information of this method are as below: /** * Return a list of the tasks that the user has recently launched, with * the most recent being first and older ones after in order. * * @param maxNum The maximum number of entries to return in the list. The * actual number returned may be smaller, depending on how many tasks the * user has started and the maximum number the system can remember. * * @return Returns a list of RecentTaskInfo records describing each of * the recent tasks. * * @throws SecurityException Throws SecurityException if the caller does * not hold the {@link android.Manifest.permission#GET_TASKS} permission. */ public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) throws SecurityException { try { return ActivityManagerNative.getDefault().getRecentTasks(maxNum, flags); } catch (RemoteException e) { // System dead, we will be dead too soon! return null; } }相信这个函数能达到你想要的结果
请问一下如果我想在gallery里放最近打开过的程序,怎么放呢?getRecentTasks(int maxNum, int flags)这个报错,说:非法修改参数getRecentTasks;只有最终是被允许的,这是什么意思呢?
帮你找了个getRecentTask的例子,希望对你有帮助,如下: public void getTaskList() { ImageButton ivIcon; ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE); PackageManager pm = this.getPackageManager(); try { List<RecentTaskInfo> list = am.getRecentTasks(64, 0); llTaskBar.removeAllViews(); for (RecentTaskInfo ti : list) { Intent intent = ti.baseIntent; ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); if (resolveInfo != null) { ivIcon = new ImageButton(this); ivIcon.setImageDrawable(resolveInfo.loadIcon(pm)); ivIcon.setFocusable(true); ivIcon.setClickable(true); ivIcon.setEnabled(true);
在ActivityManager 中 有一个publish的函数为:getRecentTasksThe information of this method are as below:/** * Return a list of the tasks that the user has recently launched, with ……帮你找了个getRecentTask的例子,希望对你有帮助,如下: public void getTaskList() { ImageButton ivIcon; ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE); PackageManager pm = this.getPackageManager(); try { List<RecentTaskInfo> list = am.getRecentTasks(64, 0); llTaskBar.removeAllViews(); for (RecentTaskInfo ti : list) { Intent intent = ti.baseIntent; ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); if (resolveInfo != null) { ivIcon = new ImageButton(this); ivIcon.setImageDrawable(resolveInfo.loadIcon(pm)); ivIcon.setFocusable(true); ivIcon.setClickable(true); ivIcon.setEnabled(true);
程序启动的时候都会由信息保存到logcat里面
查它就可以了
* Return a list of the tasks that the user has recently launched, with
* the most recent being first and older ones after in order.
*
* @param maxNum The maximum number of entries to return in the list. The
* actual number returned may be smaller, depending on how many tasks the
* user has started and the maximum number the system can remember.
*
* @return Returns a list of RecentTaskInfo records describing each of
* the recent tasks.
*
* @throws SecurityException Throws SecurityException if the caller does
* not hold the {@link android.Manifest.permission#GET_TASKS} permission.
*/
public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
throws SecurityException {
try {
return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
flags);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
return null;
}
}相信这个函数能达到你想要的结果
帮你找了个getRecentTask的例子,希望对你有帮助,如下:
public void getTaskList() {
ImageButton ivIcon;
ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
PackageManager pm = this.getPackageManager();
try {
List<RecentTaskInfo> list = am.getRecentTasks(64, 0);
llTaskBar.removeAllViews();
for (RecentTaskInfo ti : list) {
Intent intent = ti.baseIntent;
ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
if (resolveInfo != null) {
ivIcon = new ImageButton(this);
ivIcon.setImageDrawable(resolveInfo.loadIcon(pm));
ivIcon.setFocusable(true);
ivIcon.setClickable(true);
ivIcon.setEnabled(true);
ivIcon.setScaleType(ScaleType.CENTER);
ivIcon.setLayoutParams(new LinearLayout.LayoutParams(120, 120));
llTaskBar.addView(ivIcon);
}
}
} catch (SecurityException se) {
se.printStackTrace();
}
}
在ActivityManager 中 有一个publish的函数为:getRecentTasksThe information of this method are as below:/**
* Return a list of the tasks that the user has recently launched, with
……帮你找了个getRecentTask的例子,希望对你有帮助,如下:
public void getTaskList() {
ImageButton ivIcon;
ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
PackageManager pm = this.getPackageManager();
try {
List<RecentTaskInfo> list = am.getRecentTasks(64, 0);
llTaskBar.removeAllViews();
for (RecentTaskInfo ti : list) {
Intent intent = ti.baseIntent;
ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
if (resolveInfo != null) {
ivIcon = new ImageButton(this);
ivIcon.setImageDrawable(resolveInfo.loadIcon(pm));
ivIcon.setFocusable(true);
ivIcon.setClickable(true);
ivIcon.setEnabled(true);
ivIcon.setScaleType(ScaleType.CENTER);
ivIcon.setLayoutParams(new LinearLayout.LayoutParams(120, 120));
llTaskBar.addView(ivIcon);
}
}
} catch (SecurityException se) {
se.printStackTrace();
* Return a list of the tasks that the user has recently launched, with
……
frameworks/policies/base/phone/com/android/internal/policy/impl/RecentApplicationsDialog.java这个你可以借鉴一下