如何以编程方式检测检查或识别应用程序是否正在Android Go版本8.1设备上运行 [英] How to detect check or identify app is running on Android Go edition 8.1 Device programatically

查看:167
本文介绍了如何以编程方式检测检查或识别应用程序是否正在Android Go版本8.1设备上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用某些功能并减少Android Go设备上的内存消耗.我想为所有Android设备安装一个APK.

I'd like to disable some features and reduce memory consumption on Android Go Devices. I'd like to have one APK for all Android devices.

如何检测我的应用程序正在Android Go 8.1设备上运行?是否足以检查版本8.1或将8.1版本也分发到正常的Android设备上?

How do I detect that my app is running on an Android Go 8.1 Device? Is it sufficient to check for version 8.1 or will 8.1 version be distributed to normal Android Devices as well?

推荐答案

这对我有效,基于预先安装的Apps.

This works for me, based on preinstalled Apps.

如果安装了 Assistant Go Google Go 版本,则肯定是Android Go设备.

If Assistant Go or Google Go versions are installed, definitely is an Android Go device.

在极少数情况下,如果没有预先安装这些应用,我们会寻找 Gmail Go Youtube Go .

In rare cases that these apps didn't come preinstalled we look for Gmail Go and also Youtube Go preinstalled.

在带有Android 8.1(Go)的华为Y5 Lite上进行了测试.

Tested on Huawei Y5 Lite with Android 8.1 (Go).


public static boolean isAndroidGoEdition(Context context) {
    final String GMAIL_GO = "com.google.android.gm.lite";
    final String YOUTUBE_GO = "com.google.android.apps.youtube.mango";
    final String GOOGLE_GO = "com.google.android.apps.searchlite";
    final String ASSISTANT_GO = "com.google.android.apps.assistant";

    boolean isGmailGoPreInstalled = isPreInstalledApp(context, GMAIL_GO);
    boolean isYoutubeGoPreInstalled = isPreInstalledApp(context, YOUTUBE_GO);
    boolean isGoogleGoPreInstalled = isPreInstalledApp(context, GOOGLE_GO);
    boolean isAssistantGoPreInstalled = isPreInstalledApp(context, ASSISTANT_GO);

    if(isGoogleGoPreInstalled | isAssistantGoPreInstalled){
        return true;
    }
    if(isGmailGoPreInstalled && isYoutubeGoPreInstalled){
        return true;
    }

    return false;
}

private static boolean isPreInstalledApp(Context context, String packageName){
    try {
        PackageManager pacMan = context.getPackageManager();
        PackageInfo packageInfo = pacMan.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        if(packageInfo != null){
            //Check if comes with the image OS
            int mask = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
            return (packageInfo.applicationInfo.flags & mask) != 0;
        }
    } catch (PackageManager.NameNotFoundException e) {
        //The app isn't installed
    }
    return false;
}

这篇关于如何以编程方式检测检查或识别应用程序是否正在Android Go版本8.1设备上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆