0

在我的应用程序中,我必须获取用于假/模拟位置的应用程序的名称。我为此目的使用此代码:

        public static List<String> getListOfFakeLocationAppsFromAll(Context context) {
        List<String> fakeApps = new ArrayList<>();
        try {
            List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
            for (ApplicationInfo aPackage : packages) {
                boolean isSystemPackage = ((aPackage.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
                if (!isSystemPackage && hasAppPermission(context, aPackage.packageName, "android.permission.ACCESS_MOCK_LOCATION")) {
                    fakeApps.add(getApplicationName(context, aPackage.packageName));
                }
            }
        } catch (Exception e) {
            
        }
        return fakeApps;
    }

    public static boolean hasAppPermission(Context context, String app, String permission) {
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo;
            try {
                packageInfo = packageManager.getPackageInfo(app, PackageManager.GET_PERMISSIONS);
                if (packageInfo.requestedPermissions != null) {
                    for (String requestedPermission : packageInfo.requestedPermissions) {
                        if (requestedPermission.equals(permission)) {
                            return true;
                        }
                    }
                }
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            
        }
        return false;
    }

    public static String getApplicationName(Context context, String packageName) {
        String appName = packageName;
        try {
            PackageManager packageManager = context.getPackageManager();
            try {
                appName = packageManager.getApplicationLabel(packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)).toString();
            } catch (PackageManager.NameNotFoundException e){
                e.printStackTrace();
            }
        } catch (Exception e) {
            
        }
        return appName;
    }

它在 Android 版本 < 11 上运行良好。对于 Android 11,我在这些链接上找到了权限解决方案和查询解决方案: Link1

链接2

我无法理解它(下面给出的代码):

<queries>
    <intent>
        <action android:name="android.intent.action.SEND" />
        <data android:mimeType="image/jpeg" />
    </intent>
</queries>

为了检测 MockLocation 应用程序,我无法理解我必须传递给查询标记中的操作和数据的内容。

4

0 回答 0