How to know whether my App is running on Bluestacks? - android

I'm working on a special version of my App which should run in Bluestacks. It's a windows/mac application which allows to run Android apps on the computer.
I would like to implement special behaviour when the app runs in Bluestacks. Nothing complicated, maybe showing a dialog or disabling some buttons.
But for that purpose I need to know whether the app is running on a Bluestacks device. I checked the device model (Build.MODEL) and manufacturer (Build.MANUFACTURER), but I get that the device is a Samsung GT i900.
Does someone know an unambiguous way to know whether an app is running on Bluestacks?
I know it´s rather a quite localized question, but it would be fine if I get some ideas about where to look at, or what to try.

Try this:
/**
* Returns true if device is Android port to x86
*/
public static boolean isx86Port()
{
String kernelVersion = System.getProperty("os.version");
if(kernelVersion != null && kernelVersion.contains("x86")) // for BlueStacks returns "2.6.38-android-x86+"
return true;
return false;
}

try below code:
File test = new File("/data/Bluestacks.prop");
boolean isRunningInBluestacks = test.exists();

Finally I decided to build a new app for Bluestacks using an Android library. This allows me to add special behaviour for the bluestacks app.
I tried to get all the info using the Build class, but it returns the same as a Samsung Galaxy GT i9000 device, so it's impossible to know that the device is running in bluestacks.

This Will be unique.
There is no bluetooth device in Bluestack.
So try to get The Bluetooth Address string which is always 'null' on Bluestack or Any emulator.Make sure you are adding Bluetooth permission on your project manifest.
BluetoothAdapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String m_bluetoothAdd = m_BluetoothAdapter.getAddress();

Related

Android : How to detect the device is Huawei or not?

I am trying to find a way to detect whether the device is Huawei or not.
My app has a piece of code that causes a crash on Huawei devices, I want to avoid executing that code if the device is Huawei.
I don't want to use checks based on GMS & HMS availability cause my app does not contain dependency for these packages.
Thanks
Try this. The Code standard is poor, but it gets the job done. I don't think Huawei will ever change its name.
private boolean isHuaweiDevice(){
String manufacturer = android.os.Build.MANUFACTURER;
String brand = android.os.Build.BRAND;
return manufacturer.toLowerCase().contains("huawei") || brand.toLowerCase().contains("huawei");
}

Is it me, or is DevicePolicyManager.getStorageEncryptionStatus() broken?

I am trying to determine the storage encryption status of my Android device from within my application. Following the recommendations of the relevant Android Developer page, here is my code:
DevicePolicyManager mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
int encryptionStatus = mDPM.getStorageEncryptionStatus();
if (DEBUG) Log.v(TAG, "checkSecuritySettingsSufficient: encryptionStatus=" + encryptionStatus);
Here's the trouble: when I run this code on a device (I've tried it on a Motorola Droid Maxx running Android 4.4.4 and a Nexus 7 running Android 5.0.2) which I have previously encrypted, DevicePolicyManager.getStorageEncryptionStatus() will always return a value of 1, i.e. ENCRYPTION_STATUS_INACTIVE.
Android is therefore reporting that the device is not encrypted, despite the fact that the file system is definitely encrypted (I checked its status from the Settings > Security page).
Is this function broken? There doesn't seem to be any mention of that on SO or on other web sources. This leads me to believe that I am not doing something correctly with respect to DevicePolicyManager.
UPDATE After running through the encryption steps again with the Motorola device, DevicePolicyManager.getStorageEncryptionStatus() is returning the correct value, but it's still failing on the Nexus 7.
I just ran into this same issue and found out it was happening because the device had disk encryption enabled, but did not require the passcode be entered at startup. Changing the passcode, and forcing the require PIN at startup option to be true made DevicePolicyManager.getStorageEncryptionStatus() correctly return ENCRYPTION_STATUS_ACTIVE.

Assign static IP address for Wifi network on Android 3.x and 4.x

Im working on one project and there should be a functionality for setting static IP address (DNS, Netmask, Gateway) for Wifi if user want it.
My initial and actual solution is an usage of android.provider.Settings.System class that allows this feature but this solution works successfully only for Android 2.x devices.
It's nice, definitely i'm not on totally zero but it would be nice to get it work also for higher versions of Android OS. It don't know exactly why it doesn't work.
If i use this simple method for checking actual status:
public static final boolean hasStaticIp(Context c) {
try {
return Settings.System.getInt(c.getContentResolver(),
Settings.System.WIFI_USE_STATIC_IP) == 1;
}
catch (SettingNotFoundException e) {
Log.i(TAG, "Settings not found (" + e.geMessage() + ")");
return false;
}
}
it returns true for both Android 2.x and also Android 4.x but in second case, changes are definitely not reflected in Wifi I found this a little hardcoded solution but it didn't work as expected.
Is there anyone that faced against same problem?
I'll be glad for any working solution and also for rooted devices (maybe some command in linux) since it's easy to check status of whether cellphone is rooted or not.
Thanks in advance.
Now i can say: "I caught it"
I spent many days by looking for better, cleaner and for 100% working solution how actual (now i guess currently only one solution) solution with reflection is. But without result.
So i tried again to use mentioned solution with reflection here:
How to configue static IP, netmask ,gateway programmatically on
Android 3.x or 4.x
and suprisingly it works! And now i know what i was missing. So everyone who tried this solution on device with API greater than 10 (sice Honeycomb) make sure you called:
wifiManager.saveConfiguration();
it's not enough to call only
wifiManager.updateNetwork(wifiConfiguration);
bacause changes (also made via reflection) won't be permanently saved to specific WifiConfiguration.
So now it works as expected and now a little summary:
Setting static IP address for Android 1.x and 2.x :
Android 1.x and 2.x doesn't provide solution for setting static ip address per SSID (only for actual connected network) so simple working solution is to use ContentResolver and write data to System Settings via:
Settings.System.putInt(resolver, "wifi_use_static_ip", 1); // enabling static ip
Settings.System.putInt(resolver, "wifi_use_static_ip", 0); // enabling DHCP
Setting static IP address for Android 3.x and 4.x:
Since Android 3.x it's possible to set static ip address per SSID hence solution for lower versions of Android OS will not working.
Currently there is no API for this purpose so solution with reflection linked above is only one that actually works.
Notes:
Don't forget to change setGateway() for Android 3.x (also mentioned in origin thread)
Finally since if someone want to have application for setting static ip adress for Android 3.x and 4.x proper method takes netmask prefix as int and not full netmask so here is list of available netmasks with their prefixes.
Hope it helps.

Android WiFi Direct Demo Issues

im testing the new technology wifi direct and im having some issues using
the wifi direct demo from the samples that come with the android-sdk.
So, I have two devices A and B, both with android 4.0.3.
First, from device A, I send a file to B. Nothing wrong here, B
receives the file.
Then A disconnects from B.
Now, from device B I try to send a file to A.
But the device that receives the file is B, instead of A.
To fix, i need to turn off and on both devices...
Also, sometimes when i click disconnect and try to
connect again, connection fails and i have to disable and
enable wifi direct...
Anyone else experiencing this?
Is it because the new technology is not mature yet or maybe
something wrong with my build/driver/etc or maybe this demoapp
doesnt support two-way sharing.
Any ideas and/or explanations would be apreciated.
When providing a WifiP2pConfig instance to the connect() function, you can set the groupOwnerIntent property of this configuration object as follows:
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = "..."; // insert ip here
config.groupOwnerIntent = 0;
config.wps.setup = WpsInfo.PBC;
manager.connect(..., config, ...);
From the android reference:
This (the groupOwnerIntent) is an integer value between 0 and 15 where
0 indicates the least inclination to be a group owner and 15 indicates
the highest inclination to be a group owner.
Furthermore, the demo probably repeatedly sends the file to the same device because there is always made a socket connection to the ip-address obtained from:
WifiP2pInfo.groupOwnerAddress
If you would like to support bidirectional communication, the first step in setting this up would be sending the ip-address of the non group owner to the group owner.
As far as the disconnect/reconnect problem goes, I seem to have the same inconsistencies with Android 4.0.2 devices.
I have been trying for a while to transfer files between two devices using wifi direct. I have use the Android SDK WifiDirectDemo as base. My experience:
GO address is always the same (at least in Samsung Nexus), but this is not really a problem, because you can use this to know who is the server (or client).
Another strange thing was that MAC address of devices were different when you got it from Android WifiManager and when you read it from "/proc/net/arp" file.
At the end I did it, and you can see the code here.
I hope it helps you!
I have been struggling with the same problem lately. I suppose this is an OS issue. To give you a brief background, I have installed Wi-Fi Direct application to both devices with different OS versions, one with OS 4.0.1 and one with OS 4.0.2. The connection fails from time to time when I disconnect and reconnect the devices. It goes same while searching for devices too. But the thing is, this only happens on the device with OS 4.0.2. Other device does not crash or disconnect.
While searching for that problem, I have found the links below. People discussed about that and they share the same idea. Apparently this is an OS 4.0.2 issue. I am not sure if it is the same for OS 4.0.3 but there is no problem with the previous version OS 4.0.1 for sure.
Here are the links:
http://code.google.com/p/android/issues/detail?id=24402
http://osdir.com/ml/android-platform/2012-01/msg00226.html

Why InetAddress.getByName().isReachable() works on device but not on the Eclipse AVD?

I test if device is up in the network with simple piece of code:
ip_addr="172.16.1.24";
isAvailable = InetAddress.getByName(ip_addr).isReachable(2000);
That code will always return return false on my Eclipse AVD even despite the ip_addr is connectable and the subsequent request to it with http will succeed.
On the other hand if the app is installed on the accual android tablet it will work as expected and the isAvailable will true reflect the fact if the ip_addr is reachable.
This make the debug very dificult as I cant rely on the Emulator any more.

Categories

Resources