ben*_*tzy 6 java android android-8.1-oreo android-go
我想禁用某些功能并减少Android Go设备上的内存消耗。我想为所有Android设备安装一个APK。
如何检测我的应用程序正在Android Go 8.1设备上运行?检查8.1版本是否足够?是否也可以将8.1版本分发到正常的Android设备?
小智 10
这对我有用,基于预装的应用程序。
如果安装了Assistant Go或Google Go版本,则肯定是 Android Go 设备。
在极少数未预装这些应用程序的情况下,我们会寻找预装Gmail Go和Youtube Go。
在搭载 Android 8.1 (Go) 的华为 Y5 Lite 上进行测试。
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;
}
Run Code Online (Sandbox Code Playgroud)
似乎没有直接的 api 用于检索应用程序是否在 GO 版本上运行。
但您可以通过以下组合来涵盖此情况:
基于设备内存并确定应用程序的阈值:
private ActivityManager.MemoryInfo getAvailableMemory() {
ActivityManager activityManager =
(ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new
ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo;
}
Run Code Online (Sandbox Code Playgroud)对于特定型号/制造商可以采取进一步类似的步骤:
String deviceName = android.os.Build.MODEL;
String deviceMan = android.os.Build.MANUFACTURER;
Run Code Online (Sandbox Code Playgroud)希望能帮助到你。