桌面开发,只考虑主要功能,如下敲上就可以完成简陋版本
AndroidManifest.xml 主界面:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
获取应用列表
public static List<AppInfo> GetAppList(Context context) {
List<AppInfo> list = new ArrayList<AppInfo>();
PackageManager pm = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> activities = pm.queryIntentActivities(mainIntent, 0);
for (ResolveInfo info : activities) {
String packName = info.activityInfo.packageName;
if (packName.equals(context.getPackageName())) {
continue;
}
AppInfo mInfo = new AppInfo();
mInfo.setIco(drawableToBitmap(info.activityInfo.applicationInfo.loadIcon(pm)));
mInfo.setName(info.activityInfo.applicationInfo.loadLabel(pm)
.toString());
mInfo.setPackageName(packName);
Intent launchIntent = new Intent();
launchIntent.setComponent(new ComponentName(packName,
info.activityInfo.name));
mInfo.setIntent(launchIntent);
list.add(mInfo);
}
return list;
}
长按app图标应具有功能: 卸载、隐藏、更换图标、名字、打开设置详情
public static void UninstallApk(Context context, Activity activity, String pakename) {
try {
Uri packageURI = Uri.parse("package:" + pakename);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
activity.startActivityForResult(uninstallIntent, 1);
} catch (Exception e) {
DeBugDialog.debug_show_dialog(context, e.toString(), TAG);
}
}
打开应用
Intent intent = getPackageManager().getLaunchIntentForPackage(appInfos.get(position).getPackageName());
if (intent != null) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
打开应用设置界面
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", appInfos.get(position).getPackageName(), null));
startActivity(intent);
|