I expect that my android application is allowed to install only on real device, and android-emulator can't.How can I limit my android application installed on real device only ?
Thanks for any replies.
There's one way how to handle it. Just check device id (IMEI code). For emulator it's always null, so you can define either someone tries to launch it in real device or in emulator.
TelephonyManager tm=(TelephonyManager )activity.getSystemService(Context.TELEPHONY_SERVICE);
if(tm==null || !this.hasTelephony())
{
Log.v(TAG, "Can't get telephony service. Forcing shut down!");
return false;
}
String deviceId=tm.getDeviceId();
if(deviceId==null || deviceId.length() < 2)
{
Log.v(TAG, "Looks like emulator - bail out!");
Toast.makeText(activity, "This special version not intended to run in this device!", 5000).show();
return false;
}
Unfortunately you cannot stop people from installing in emulator, but if you have Google Licensing installed it will make sure that it does not run on unlicensed devices.
Related
Is there any way to detect if a mobile session on my android app is in android USB debugging mode or developer mode, or otherwise running automation via tools such as appium
The simplest way:
if (BuildConfig.DEBUG) {
return "debug";
}else {
return "not debug";
}
Depending on what your are doing there may be a better way, just Google Buildconfig.Degug
I am designing a chat application with registered phone number for both iOS and android app.
I want to make sure that this number and app works on one phone at a time, as below scenarios given I want to make sure that app once authenticated to another device with same account details disable the previous device.
1) app installed on one iOS device registered account and deleted and reinstalled on same device again
2) app installed on iOS phone then same account is validated on android app the iOS phone app should show disabled account
3) app installed on two android phone with same number should disable old one automatically.
Reason is I don't want multiple copies of application with same number running to avoid like whatsapp does.
I am thinking of device keychain for iOS and android Mac Id usage to get this worked out since apple stopped UDID broadcasting to server.
Also have a vague Idea about this vendor id apple providing.
Can anyone advice on this. How can I achieve so app is running with same account on one phone only and other just stops.
If you are binding an app with a phone number getting registered then it can run only on one device since you can't have same ph number running on 1+ devices at the same time. From user's perspective if he is changing same number between multiple handsets, going by your case, this app is blocking previous device of user, it sounds like a never ending loop. Everytime user's previous device is getting blocked or it may result in blocking all user's device. Dosen't make sense to me at least.
Below method is for getting device ID
public static String getDeviceID(Context p_context) throws Throwable
{
String m_deviceID = null;
TelephonyManager m_telephonyManager = null;
m_telephonyManager = (TelephonyManager) p_context
.getSystemService(Context.TELEPHONY_SERVICE);
m_deviceID = m_telephonyManager.getDeviceId().toString();
if (m_deviceID == null || "00000000000000".equalsIgnoreCase(m_deviceID))
{
m_deviceID = "AAAAAAA";
}
return m_deviceID;
}
More information about the identification you can read here.
I'm facing a problem in android version 4.3 to control airplane mode by code.For this I converted the user app into system using system/ app mover application available in google play.Once the user enables the airplane mode, the background service have the control to check the airplane mode and reset it to off state and send the broadcast changes to the device.Below the snippet I implemented in my code to keep the airplane mode state in off.But it fails in android version 4.3. It throws an exception called "permission denied". Let me know is these any additional permission need to added in manifest or else let me know your suggestions on these issue to fixed.
try {
Settings.Global.putInt(context.getContentResolver(),
"airplane_mode_on", 0);
isAirplaneModeOn = isAirplaneModeOn(context);
Intent localIntent2 = new Intent(
"android.intent.action.AIRPLANE_MODE");
localIntent2.putExtra("state", isAirplaneModeOn);
context.sendBroadcast(localIntent2);
} catch (Exception e) {
Log.v("TAG",
e.toString() + "\n" + e.getMessage());
}
Moving an App into the /system/app folder does not turn it into a System App - it simply makes the App uninstallable because /system is normally mounted read-only.
What you are trying to do requires full System App privileges. You can only get these by signing your app with the same key used to sign the original firmware Apps - the platform key. In other words, you need access to whoever built the version of Android you are running on and get them to sign your APK.
Actually you cannot do it starting from Android 4.2. Because that settings was relocated here from either Settings.System or Settings.Secure. But on previous vesions it works fine.
http://developer.android.com/about/versions/android-4.2.html
If your app is currently making changes to settings previously defined
in Settings.System (such as AIRPLANE_MODE_ON), then you should expect
that doing so will no longer work on a device running Android 4.2 or
higher if those settings were moved to Settings.Global.
Related question on StackOverflow
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();
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Determine if running on a rooted device
How do you determine (programmatically) if an Android device is: rooted Running a cracked copy of your software or rom.
I have some sensitive information in my database, and I would like to encrypt it when the phone is rooted aka the user has access to the database. How do I detect that?
Rooting detection is a cat and mouse game and it is hard to make rooting detection that will work on all devices for all cases.
See Android Root Beer https://github.com/scottyab/rootbeer for advanced root detection which also uses JNI and native CPP code compiled into .so native library.
If you need some simple and basic rooting detection check the code below:
/**
* Checks if the device is rooted.
*
* #return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/
public static boolean isRooted() {
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e1) {
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command) {
boolean executedSuccesfully;
try {
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
} catch (Exception e) {
executedSuccesfully = false;
}
return executedSuccesfully;
}
Probably not always correct. Tested on ~10 devices in 2014.
If the information is sensitive you should probably just encrypt it for all users. Otherwise a user could install your app unrooted, then root and read your database once the data's been written.
The official licensing guide says:
A limitation of the legacy
copy-protection mechanism on Android
Market is that applications using it
can be installed only on compatible
devices that provide a secure internal
storage environment. For example, a
copy-protected application cannot be
downloaded from Market to a device
that provides root access, and the
application cannot be installed to a
device's SD card.
It seems that you would benefit from using that legacy cop-protection to prevent your application from being installed on rooted devices.
You might release a separate version that can be installed on rooted devices with an encrypted database.