version:6.9
fix: update:增加app通过类名启动
This commit is contained in:
@@ -3,16 +3,18 @@ package com.uiui.aios.bean;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DesktopIcon implements Serializable , Parcelable {
|
||||
public class DesktopIcon implements Serializable, Parcelable {
|
||||
private static final long serialVersionUID = 3358230413497783708L;
|
||||
|
||||
String packageName;
|
||||
String className;
|
||||
Drawable icon;
|
||||
String lable;
|
||||
int position;
|
||||
@@ -59,6 +61,14 @@ public class DesktopIcon implements Serializable , Parcelable {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public Drawable getIcon() {
|
||||
return icon;
|
||||
}
|
||||
@@ -83,22 +93,24 @@ public class DesktopIcon implements Serializable , Parcelable {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public static DesktopIcon creatDesktopIcon(Context context, ApplicationInfo applicationInfo) {
|
||||
public static DesktopIcon creatDesktopIcon(Context context, ResolveInfo resolveInfo) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
DesktopIcon desktopIcon = new DesktopIcon();
|
||||
desktopIcon.setPackageName(applicationInfo.packageName);
|
||||
desktopIcon.setIcon(applicationInfo.loadIcon(pm));
|
||||
desktopIcon.setLable(applicationInfo.loadLabel(pm).toString());
|
||||
desktopIcon.setPackageName(resolveInfo.activityInfo.packageName);
|
||||
desktopIcon.setClassName(resolveInfo.activityInfo.name);
|
||||
desktopIcon.setIcon(resolveInfo.loadIcon(pm));
|
||||
desktopIcon.setLable(resolveInfo.loadLabel(pm).toString());
|
||||
desktopIcon.setPosition(0);
|
||||
return desktopIcon;
|
||||
}
|
||||
|
||||
public static DesktopIcon creatDesktopIcon(Context context, ApplicationInfo applicationInfo, int position) {
|
||||
public static DesktopIcon creatDesktopIcon(Context context, ResolveInfo resolveInfo, int position) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
DesktopIcon desktopIcon = new DesktopIcon();
|
||||
desktopIcon.setPackageName(applicationInfo.packageName);
|
||||
desktopIcon.setIcon(applicationInfo.loadIcon(pm));
|
||||
desktopIcon.setLable(applicationInfo.loadLabel(pm).toString());
|
||||
desktopIcon.setPackageName(resolveInfo.activityInfo.packageName);
|
||||
desktopIcon.setClassName(resolveInfo.activityInfo.name);
|
||||
desktopIcon.setIcon(resolveInfo.loadIcon(pm));
|
||||
desktopIcon.setLable(resolveInfo.loadLabel(pm).toString());
|
||||
desktopIcon.setPosition(position);
|
||||
return desktopIcon;
|
||||
}
|
||||
|
||||
@@ -193,14 +193,14 @@ public class AppListFragment extends BaseFragment {
|
||||
ToastUtil.show("电话功能被禁用");
|
||||
return;
|
||||
} else {
|
||||
ApkUtils.openPackage(v.getContext(), desktopIcon.getPackageName());
|
||||
ApkUtils.openPackage(v.getContext(), desktopIcon.getPackageName(), desktopIcon.getClassName());
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(desktopIcon.getPackageName());
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
SendRunningApp(getActivity());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ApkUtils.openPackage(v.getContext(), desktopIcon.getPackageName());
|
||||
ApkUtils.openPackage(v.getContext(), desktopIcon.getPackageName(), desktopIcon.getClassName());
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(desktopIcon.getPackageName());
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
SendRunningApp(getActivity());
|
||||
@@ -211,6 +211,7 @@ public class AppListFragment extends BaseFragment {
|
||||
@Override
|
||||
public void onLongClick(View v, int index) {
|
||||
DesktopIcon desktopIcon = mDesktopIcons.get(index);
|
||||
if (desktopIcon == null) return;
|
||||
String pkg = desktopIcon.getPackageName();
|
||||
Log.e(TAG, "onLongClick: " + pkg);
|
||||
switch (pkg) {
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -50,7 +49,7 @@ public class ApkUtils {
|
||||
this.add("com.sprd.sprdnote");
|
||||
this.add("com.android.deskclock");
|
||||
this.add("com.android.email");
|
||||
this.add("com.android.calendar");
|
||||
// this.add("com.android.calendar");
|
||||
this.add("com.android.uiuios");
|
||||
this.add("com.uiui.os");
|
||||
this.add("com.uiui.health");
|
||||
@@ -80,6 +79,7 @@ public class ApkUtils {
|
||||
this.add("com.jxw.launcher");
|
||||
this.add("com.tencent.android.qqdownloader");
|
||||
this.add("com.alldocube.store");
|
||||
this.add("com.android.calendar");
|
||||
}};
|
||||
private static HashSet<String> allHintPackage = new HashSet<String>() {{
|
||||
this.add("com.android.uiuios");
|
||||
@@ -150,8 +150,7 @@ public class ApkUtils {
|
||||
public static ArrayList<DesktopIcon> queryFilterAppInfo(Context context) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
// 查询所有已经安装的应用程序
|
||||
List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的
|
||||
ArrayList<ApplicationInfo> applicationInfos = new ArrayList<>();
|
||||
List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
|
||||
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
|
||||
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
|
||||
@@ -169,66 +168,58 @@ public class ApkUtils {
|
||||
if (!TextUtils.isEmpty(appListString)) {
|
||||
packageList = new ArrayList<>(Arrays.asList(appListString.split(",")));
|
||||
}
|
||||
|
||||
int setting_other_appInstaller = Settings.Global.getInt(context.getContentResolver(), "setting_other_appInstaller", 1);
|
||||
|
||||
for (ApplicationInfo app : appInfos) {
|
||||
if (appIsDisable(context, app.packageName)) {
|
||||
Log.e(TAG, "queryFilterAppInfo: disable = " + app.packageName);
|
||||
for (ResolveInfo resolveInfo : resolveinfoList) {
|
||||
String pkg = resolveInfo.activityInfo.packageName;
|
||||
if (appIsDisable(context, pkg)) {
|
||||
Log.e(TAG, "queryFilterAppInfo: disable = " + pkg);
|
||||
continue;
|
||||
}
|
||||
if ((app.flags & ApplicationInfo.FLAG_SYSTEM) > 0)//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
if (isSystemApp(context, pkg))//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
{
|
||||
if (showPackageName.contains(app.packageName)) {
|
||||
applicationInfos.add(app);
|
||||
if (showPackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
} else {
|
||||
if (setting_other_appInstaller == 0) {//不显示自己安装的
|
||||
if (packageList.contains(app.packageName)){
|
||||
applicationInfos.add(app);
|
||||
if (packageList.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
}else {
|
||||
if (allowPackages.contains(app.packageName) && !excludePackageName.contains(app.packageName)) {
|
||||
applicationInfos.add(app);
|
||||
} else {
|
||||
if (allowPackages.contains(pkg) && !excludePackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Settings.Global.getInt(context.getContentResolver(), "is_activity", 0) == 0) {
|
||||
applicationInfos.removeIf(applicationInfo -> "com.uiui.city".equals(applicationInfo.packageName));
|
||||
// applicationInfos.removeIf(applicationInfo -> "com.uiui.sn".equals(applicationInfo.packageName));
|
||||
resolveInfos.removeIf(resolveInfo -> "com.uiui.city".equals(resolveInfo.activityInfo.packageName));
|
||||
// resolveInfos.removeIf(applicationInfo -> "com.uiui.sn".equals(applicationInfo.packageName));
|
||||
}
|
||||
applicationInfos.sort(new Comparator<ApplicationInfo>() {
|
||||
resolveInfos.sort(new Comparator<ResolveInfo>() {
|
||||
@Override
|
||||
public int compare(ApplicationInfo o1, ApplicationInfo o2) {
|
||||
public int compare(ResolveInfo o1, ResolveInfo o2) {
|
||||
return Collator.getInstance(Locale.CHINESE).compare(o1.loadLabel(pm).toString(), o2.loadLabel(pm).toString());
|
||||
// return o1.loadLabel(pm).toString().compareTo(o2.loadLabel(pm).toString());
|
||||
}
|
||||
});
|
||||
applicationInfos.sort(new Comparator<ApplicationInfo>() {
|
||||
resolveInfos.sort(new Comparator<ResolveInfo>() {
|
||||
@Override
|
||||
public int compare(ApplicationInfo o1, ApplicationInfo o2) {
|
||||
if ((o1.flags & ApplicationInfo.FLAG_SYSTEM) <= (o2.flags & ApplicationInfo.FLAG_SYSTEM)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
public int compare(ResolveInfo o1, ResolveInfo o2) {
|
||||
try {
|
||||
if ((pm.getApplicationInfo(o1.activityInfo.packageName, 0).flags & ApplicationInfo.FLAG_SYSTEM) <= (pm.getApplicationInfo(o2.activityInfo.packageName, 0).flags & ApplicationInfo.FLAG_SYSTEM)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
ArrayList<DesktopIcon> desktopIcons = new ArrayList<>();
|
||||
HashMap<String, ApplicationInfo> infoHashMap = new HashMap<>();
|
||||
for (ApplicationInfo applicationInfo : applicationInfos) {
|
||||
infoHashMap.put(applicationInfo.packageName, applicationInfo);
|
||||
}
|
||||
for (int i = 0; i < defaultSort.size(); i++) {
|
||||
ApplicationInfo info = infoHashMap.get(defaultSort.get(i));
|
||||
if (info != null) {
|
||||
desktopIcons.add(DesktopIcon.creatDesktopIcon(context, info, i));
|
||||
infoHashMap.remove(defaultSort.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
for (ApplicationInfo applicationInfo : infoHashMap.values()) {
|
||||
for (ResolveInfo applicationInfo : resolveInfos) {
|
||||
desktopIcons.add(DesktopIcon.creatDesktopIcon(context, applicationInfo));
|
||||
}
|
||||
DesktopIcon exitIcon = new DesktopIcon();
|
||||
@@ -244,6 +235,18 @@ public class ApkUtils {
|
||||
return pm.getApplicationEnabledSetting(pkg) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
}
|
||||
|
||||
public static boolean isSystemApp(Context context, String pkg) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
ApplicationInfo applicationInfo = null;
|
||||
try {
|
||||
applicationInfo = pm.getApplicationInfo(pkg, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (applicationInfo == null) return false;
|
||||
return (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0;
|
||||
}
|
||||
|
||||
public static boolean disableApp(Context context, String pkg) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
try {
|
||||
@@ -319,6 +322,20 @@ public class ApkUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean openPackage(Context context, String packageName, String className) {
|
||||
if (TextUtils.isEmpty(className)) {
|
||||
return openPackage(context, packageName);
|
||||
}
|
||||
ComponentName cn = new ComponentName(packageName, className);
|
||||
Intent intent = new Intent();
|
||||
intent.setComponent(cn);
|
||||
if (context != null) {
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Context getPackageContext(Context context, String packageName) {
|
||||
Context pkgContext = null;
|
||||
if (context.getPackageName().equals(packageName)) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public class IconUtils {
|
||||
this.add("com.android.deskclock");//时钟
|
||||
this.add("com.android.dialer");//电话
|
||||
this.add("com.android.dialer");//电话
|
||||
this.add("com.android.gallery3d");//图库
|
||||
// this.add("com.android.gallery3d");//图库
|
||||
this.add("com.android.mms");//信息
|
||||
this.add("com.android.mms.ui");//信息
|
||||
this.add("com.android.messaging");//信息
|
||||
@@ -60,7 +60,7 @@ public class IconUtils {
|
||||
this.add("com_android_deskclock");
|
||||
this.add("com_android_dialer");
|
||||
this.add("com_android_dialer");
|
||||
this.add("com_android_gallery3d_app");
|
||||
// this.add("com_android_gallery3d_app");
|
||||
this.add("com_android_mms_ui");
|
||||
this.add("com_android_mms_ui");
|
||||
this.add("com_android_mms_ui");
|
||||
|
||||
Reference in New Issue
Block a user