Android: improve check to know if running on ChromeBook or emulator.

https://stackoverflow.com/questions/39784415/how-to-detect-programmatically-if-android-app-is-running-in-chrome-book-or-in
This commit is contained in:
Sylvain
2025-08-22 10:43:46 +02:00
committed by Sam Lantinga
parent 95c44dcdc3
commit e55f636d1e
3 changed files with 13 additions and 6 deletions

View File

@@ -161,7 +161,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
mDevice = device; mDevice = device;
mDeviceId = mManager.getDeviceIDForIdentifier(getIdentifier()); mDeviceId = mManager.getDeviceIDForIdentifier(getIdentifier());
mIsRegistered = false; mIsRegistered = false;
mIsChromebook = mManager.getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management"); mIsChromebook = SDLActivity.isChromebook();
mOperations = new LinkedList<GattOperation>(); mOperations = new LinkedList<GattOperation>();
mHandler = new Handler(Looper.getMainLooper()); mHandler = new Handler(Looper.getMainLooper());

View File

@@ -108,7 +108,7 @@ public class HIDDeviceManager {
HIDDeviceRegisterCallback(); HIDDeviceRegisterCallback();
mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE); mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE);
mIsChromebook = mContext.getPackageManager().hasSystemFeature("org.chromium.arc.device_management"); mIsChromebook = SDLActivity.isChromebook();
// if (shouldClear) { // if (shouldClear) {
// SharedPreferences.Editor spedit = mSharedPreferences.edit(); // SharedPreferences.Editor spedit = mSharedPreferences.edit();

View File

@@ -1331,10 +1331,17 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static boolean isChromebook() { public static boolean isChromebook() {
if (getContext() == null) { // https://stackoverflow.com/questions/39784415/how-to-detect-programmatically-if-android-app-is-running-in-chrome-book-or-in
return false; if (getContext() != null) {
if (getContext().getPackageManager().hasSystemFeature("org.chromium.arc")
|| getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management")) {
return true;
}
} }
return getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management");
// Running on AVD emulator
boolean isChromebookEmulator = (Build.MODEL != null && Build.MODEL.startsWith("sdk_gpc_"));
return isChromebookEmulator;
} }
/** /**
@@ -2117,7 +2124,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
int requestCode; int requestCode;
boolean multipleChoice; boolean multipleChoice;
} }
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */