How to detect android app is running on Bluestacks emulator - android

I need to disable app from running on emulators so I somehow combined answers of this question. It's working on most emulators but it can't detect blustacks. I can not find a robust way to detect blustacks as it has most of a real device properties.
I found safeToRun library that using Build.BOOTLOADER == OsCheckConstants.UNKNOWN to detect blustacks but I'm not sure that only this condition is enough to make sure the running device is a blustacks emulator and I'm afraid that some real devices return "unknown" as bootloader parameter.
it is worth mentioning that this block of code can't detect bluestacks too (glGetString returns null)
try {
String opengl = android.opengl.GLES20.glGetString(android.opengl.GLES20.GL_RENDERER);
if (opengl != null) {
if (opengl.contains("Bluestacks") ||
opengl.contains("Translator")
)
newRating += 10;
}
} catch (Exception e) {
e.printStackTrace();
}
any ideas or solutions?

Related

How to programmatically detect if an app is running on a Samsung "Edge" screen?

Is there an API to use to determine if the device an app is running on happens to be one of the Samsung "Edge" devices? That is, a device with a rounded edge as opposed to the one with the right-angled edges. (I believe Samsung is the only one manufacturing these at the moment.)
Additionally, some of the older "Edge" devices had only one rounded edge, while the newer ones have two. Is it possible to differentiate between these cases: no rounded edges, one rounded edge, two rounded edges?
I've encounter this problem too, after reading at the SDK docs, inspect the jar, and a few try and error; This is the method I use to check Samsung Edge devices (i.e Samsung Galaxy S8/S9.) without adding SDK libraries.
internal fun isEdgeDevice(): Boolean {
var hasCocktailPanel = false
try {
val sLookImplClass = Class.forName("com.samsung.android.sdk.look.SlookImpl")
if (sLookImplClass != null) {
val isFeatureEnabledMethod =
sLookImplClass.getDeclaredMethod("isFeatureEnabled", Int::class.java)
hasCocktailPanel = isFeatureEnabledMethod.invoke(null, 7) as Boolean
}
} catch (ignored: Exception) {
}
return hasCocktailPanel
}
Explanation:
This method try to find SlookImpl class.
If it found one, then we can query the COCKTAIL_PANEL availability.
Note: Before calling isEdgeDevice() method, I will check if the Build.MANUFACTURER and Build.BRAND is "samsung", then I will proceed to check whether its edge device or not.

Latest android no longer sends UDP broadcast packets

So we have been running the following code on android (Samsung Note 4) and iOS with out trouble until the latest phones started coming out with android 7+ (Samsung S8, OnePlus3T). We would send out our broadcast to identify other systems that would respond to this message. Now we find that UDP is blocked on the phone.
We have used Evothings to test that UDP is blocked. Programmatically I don't think I am missing anything to make this work.
We have noticed a change with the way WiFi works on android. If the WiFi connection doesn't have internet, the system seems to behave differently.
chrome.system.network.getNetworkInterfaces(function (networkIfaceArray) {
for (var i = 0; i < networkIfaceArray.length; i++) {
var iface = networkIfaceArray[i];
if (iface.prefixLength < 32) {
addr_array = parseIP(iface.address);
mask = 32 - iface.prefixLength;
mask = Math.pow(2, mask) - 1;
pointer = 3;
while (mask > 255) {
addr_array[pointer++] = 255;
mask -= 255;
}
addr_array[pointer] = mask;
udp_sock.send(app.socketId, message,
addr_array.join("."), 5000, function (sendInfo) {
//check for response
});
}
}
});
We have tried this answer where they suggest different ports. Most of the posts here are older than version 7 and so don't address our problem.
Again, it still works with the older versions of android and iOS. If you have come across this problem please share.
You should try to use the setBroadcast() function. Old versions of the cordova plugin did not have it implemented, see https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-udp/issues/7, so you may have to check if it is defined before using it. Possibly the Evothings app uses an older version of the cordova plugin. Maybe the newer Android devices default the broadcast option off, so calling setBroadcast() should allow it to work.
// Set Broadcast (if available)
if (chrome.sockets.udp.setBroadcast != undefined) {
chrome.sockets.udp.setBroadcast(app.socketId, true, function (result) {
if (result < 0) {
console.log("setBroadcast failed");
}
else {
console.log("setBroadcast worked");
}
});
}

Does BluetoothLeAdvertiser work on a Nexus 5 with Android 5.0?

After flashing my Nexus 5 to the Android 5.0 preview release hammerhead-lpx13d, the OS reports that it no longer supports Bluetooth LE advertising. If you call:
((BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter().getBluetoothLeAdvertiser()
always returns null. In addition, the new method:
((BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter().isMultipleAdvertisementSupported()
always returns false
The first method used to return a valid object on the first Android L preview release for the Nexus 5 back in June. It no longer does, after flashing the latest update.
Does anybody see otherwise?
EDIT: This has been reproduced by at least one person, who opened an issue with Google here: https://code.google.com/p/android-developer-preview/issues/detail?id=1570
Unfortunately, the official answer from Google is no, the Nexus 5 no longer supports advertising.
We introduced BLE peripheral mode in Android 5.0 Lollipop. Nexus 6 and
Nexus 9 are the first two production Nexus devices that support BLE
peripheral mode. Due to hardware chipset dependency, older Nexus
devices (4/5/7) will not have access to the feature on Lollipop.
See Comment #52 on issue 1570 by danielho...#google.com: BLE advertise mode not working
https://code.google.com/p/android-developer-preview/issues/detail?id=1570
That said, I have confirmed that advertising is supported by the Nexus 9 tablet. See here for details: http://developer.radiusnetworks.com/2014/11/18/beacon-transmission-with-android-5.html
This is not full a solution, but a proposed work-around posted by mattprec on Google Code. It allows you to get a BluetoothLeAdvertiser instance by calling the private constructor rather than using the public API. Unfortunately, reports of testing on a Nexus 5 and a Nexus 7 2013 edition say that even after you get an instance you can't use the object to make advertisements come out. Also, be warned that even if you can get it to work, it might break on any minor code release of Android because it is using a non-public API.
For the record, here's the code snippet copied from that page:
private static BluetoothLeAdvertiser getAdvertiserHack(BluetoothAdapter adapter) {
try {
Class<? extends BluetoothAdapter> adapterClass = adapter.getClass();
Field advertiserField = adapterClass.getDeclaredField("sBluetoothLeAdvertiser");
advertiserField.setAccessible(true);
Object advertiser = advertiserField.get(adapter);
if (advertiser == null) {
Field bluetoothManagerServiceField = adapterClass.getDeclaredField("mManagerService");
bluetoothManagerServiceField.setAccessible(true);
Object bluetoothManagerService = bluetoothManagerServiceField.get(adapter);
Constructor<?> constructor = BluetoothLeAdvertiser.class.getDeclaredConstructor(
bluetoothManagerServiceField.getType());
constructor.setAccessible(true);
advertiser = constructor.newInstance(bluetoothManagerService);
advertiserField.set(adapter, advertiser);
}
return (BluetoothLeAdvertiser) advertiser;
} catch (Exception e) {
return null;
}
}
That said, I have confirmed that advertising is supported by the Nexus
9 tablet. See here for details:
http://developer.radiusnetworks.com/2014/11/18/beacon-transmission-with-android-5.html
QuickBeacon app is working fine on Nexus 9. In app there is a Beacon Format option.#davidgyoung Could you give exact String for BeaconParser to make this library transmit in iBeacon format?
UPDATE:
Related question up to android-beacon-library/BLE Android SDK. Is there possibility - without calling startAdvertising method - to check if there is advertising service running in background?
UPDATE:
Recording to this : https://code.google.com/p/android-developer-preview/issues/detail?id=1570#c52
Now only Nexus 6 and Nexus 9 supports BLE Peripheal Mode in Android 5.0
UPDATE:
I work on Nexus 5 Android 5.0 build number LPX13D
according to this https://stackoverflow.com/a/26611779/1906420
After implementig your workaround bluetoothAdvertiser is not null. Calling startAdvertising from bluetoothAdvertiser
bluetoothAdvertiser.startAdvertising(settingsBuilder.build(), dataBuilder.build(), advertiseCallback);
where
private AdvertiseCallback advertiseCallback = new AdvertiseCallback() {
#Override
public void onStartSuccess(AdvertiseSettings settingsInEffec) {
}
#Override
public void onStartFailure(int result) {
if (result == ADVERTISE_FAILED_DATA_TOO_LARGE) {
Log.d(TAG, "Failed to start advertising as the advertise data to be broadcasted is larger than 31 bytes.");
}
else if(result == ADVERTISE_FAILED_TOO_MANY_ADVERTISERS){
Log.d(TAG, "Failed to start advertising because no advertising instance is available.");
}
else if(result == ADVERTISE_FAILED_ALREADY_STARTED){
Log.d(TAG, "Failed to start advertising as the advertising is already started.");
}
else if(result == ADVERTISE_FAILED_INTERNAL_ERROR){
Log.d(TAG, "Operation failed due to an internal error.");
}
else if(result == ADVERTISE_FAILED_FEATURE_UNSUPPORTED){
Log.d(TAG, "This feature is not supported on this platform.");
}
else {
Log.d(TAG, "There was unknown error.");
}
}
};
always give callback onStartFailure with error code 5 ( ADVERTISE_FAILED_FEATURE_UNSUPPORTED )

How to prevent name caching and detect bluetooth name changes on discovery

I'm writing an Android app which receives information from a Bluetooth device. Our client has suggested that the Bluetooth device (which they produce) will change its name depending on certain conditions - for the simplest example its name will sometimes be "xxx-ON" and sometimes "xxx-OFF". My app is just supposed to seek this BT transmitter (I use BluetoothAdapter.startDiscovery() ) and do different things depending on the name it finds. I am NOT pairing with the Bluetooth device (though I suppose it might be possible, the app is supposed to eventually work with multiple Android devices and multiple BT transmitters so I'm not sure it would be a good idea).
My code works fine to detect BT devices and find their names. Also, if the device goes off, I can detect the next time I seek, that it is not there. But it seems that if it is there and it changes name, I pick up the old name - presumably it is cached somewhere. Even if the bluetooth device goes off, and we notice that, the next time I detect it, I still see the old name.
I found this issue in Google Code: here but it was unclear to me even how to use the workaround given ("try to connect"). Has anyone done this and had any luck? Can you share code?
Is there a simple way to just delete the cached names and search again so I always find the newest names? Even a non-simple way would be good (I am writing for a rooted device).
Thanks
I would suggest 'fetchUuidsWithSdp()'. It's significance is that, unlike the similar getUuids() method, fetchUuidsWithSdp causes the device to update cached information about the remote device. And I believe this includes the remote name as well as the SPD.
Note that both the methods I mentioned are hidden prior to 4.0.3, so your code would look l ike this:
public static void startServiceDiscovery( BluetoothDevice device ) {
// Need to use reflection prior to API 15
Class cl = null;
try {
cl = Class.forName("android.bluetooth.BluetoothDevice");
} catch( ClassNotFoundException exc ) {
Log.e(CTAG, "android.bluetooth.BluetoothDevice not found." );
}
if (null != cl) {
Class[] param = {};
Method method = null;
try {
method = cl.getMethod("fetchUuidsWithSdp", param);
} catch( NoSuchMethodException exc ) {
Log.e(CTAG, "fetchUuidsWithSdp not found." );
}
if (null != method) {
Object[] args = {};
try {
method.invoke(device, args);
} catch (Exception exc) {
Log.e(CTAG, "Failed to invoke fetchUuidsWithSdp method." );
}
}
}
}
You'll then need to listen for the BluetoothDevice.ACTION_NAME_CHANGED intent, and extract BluetoothDevice.EXTRA_NAME from it.
Let me know if that helps.

How to detect android front camera programmatically

Can anyone tell me how to check if the android phone has a front camera too? I'd tried to use some help form https://docs.google.com/View?id=dhtsnvs6_57d2hpqtgr but Camera camera = FrontFacingCamera.getFrontFacingCamera(); sometimes works sometimes not.
Any help please?
Can anyone tell me how to check if the android phone has a front camera too?
There is no API for this, at least through Android 2.2. Sorry!
I'd tried to use some help form https://docs.google.com/View?id=dhtsnvs6_57d2hpqtgr but Camera camera = FrontFacingCamera.getFrontFacingCamera(); sometimes works sometimes not.
That is for two specific models of phones, not for Android devices in general. With luck, the upcoming Gingerbread release will add built-in support for front-facing cameras.
In the meantime, you need to get the instructions (like the one you linked to) from each and every device manufacturer and attempt to follow them.
private boolean hasFlash() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
try {
if(camManager==null)
camManager=(CameraManager)getSystemService( CAMERA_SERVICE );
String cameraId = camManager.getCameraIdList()[1];
CameraCharacteristics cameraCharacteristics = camManager.getCameraCharacteristics( cameraId );
return cameraCharacteristics.get( CameraCharacteristics.FLASH_INFO_AVAILABLE );
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}

Categories

Resources