android recenttaskinfo获取应用缩略图
时间: 2023-07-16 07:14:46 浏览: 195
android 获取最近应用
5星 · 资源好评率100%
要获取应用程序的缩略图,可以使用以下步骤:
1.获取最近任务列表:
```
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasks(1, ActivityManager.RECENT_WITH_EXCLUDED);
if (recentTasks != null && recentTasks.size() > 0) {
ActivityManager.RecentTaskInfo recentTask = recentTasks.get(0);
if (recentTask != null) {
Intent intent = recentTask.baseIntent;
ComponentName componentName = intent.getComponent();
String packageName = componentName.getPackageName();
}
}
```
2.使用PackageManager获取应用程序的图标
```
PackageManager pm = getPackageManager();
Drawable appIcon = pm.getApplicationIcon(packageName);
```
3.将Drawable转换为Bitmap
```
Bitmap appBitmap = ((BitmapDrawable) appIcon).getBitmap();
```
4.对Bitmap进行缩放
```
Bitmap scaledBitmap = Bitmap.createScaledBitmap(appBitmap, width, height, true);
```
5.设置ImageView显示缩略图
```
imageView.setImageBitmap(scaledBitmap);
```
阅读全文