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

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");
}

Related

Process.getExclusiveCores() throws exception on certain devices

My Android app is currently in open beta and I am receiving crash reports from my beloved testers. Audio processing is the app's primary focus therefore the render thread is cpu intensive and time sensitive. In an attempt to achieve the best performance possible, I am reserving exclusive cores for the process by calling:
int exclusiveCores[] = {};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
exclusiveCores = android.os.Process.getExclusiveCores();
}
then sending the int array on through the JNI to be handled by the engine.
This has worked fine until recently when I received a crash report stating a RuntimeException was thrown on the getExclusiveCores() call. The device was a Samsung J7 (SM-J727T) running Android 7.0. This is the only device so far that has given me this report.
Has anyone else experienced this issue? Is this API not available for this specific device? Is there another limitation I should be checking for before calling getExclusiveCores?
The documentation states:
To support an exclusive core on a device:
Enable cpusets and configure a cpuset that contains only the top foreground application.
Ensure one core (this is the exclusive core) is reserved for threads from this cpuset.
but I am unable to find any other documentation on how to enable cpusets and configure a cpuset.
Can anyone provide an example of this implementation or point me in the right direction?
Also, I personally do not have this device and Firebase Testlab does not have this device running android 7.0 so testing any solution will have its own complications.
Thanks
I also ran into this on a Samsung Galaxy S6 running Android 7.0.
Unfortunately it looks like getExclusiveCores isn't implemented on some devices (despite being a mandatory API, specified in the Android CDD).
The best advice is to wrap calls to this method in a try/catch block and catch the RuntimeException:
try {
exclusiveCores = android.os.Process.getExclusiveCores();
} catch (RuntimeException e){
Log.w(TAG, "getExclusiveCores() is not supported on this device.");
}

How to fetch Device Name (NOT Build.MODEL) from Android programatically?

I have been searching for code through which I can fetch Device's name defined by user for his own device .
Have gone through various stackoverflow questions , but none seems to work for me ?
Image as seen in below : Will require Thanks Thanks (SM-T211 ) from android code
Try this:
String ownerInfo = Settings.Secure.getString(getContentResolver(),
"lock_screen_owner_info");
As of Android 4.4.2 the owner info value is moved to lock screen database,/data/system/locksettings.db to which 3rd-party apps have no read/write access. That's, there is no reliable way of reading owner info for later Android versions except for rooted device.
You need to get build.prop file of system which is possible either if your device is rooted or if your has system privileges....
heres the code you may follow to get and edit build.prop
Check this App in Play Store. build.prop Editor. Since it's open source, and the code is extremely simple, you can use it as a stating point: https://github.com/nathanpc/Build.prop-Editor
Try this :
BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
String deviceName = myDevice.getName();
Make sure you add to your manifest:
<uses-permission android:name="android.permission.BLUETOOTH"/>

Maintain single device for registering account of my app

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.

How to know whether my App is running on Bluestacks?

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();

Identify if device is Kindle

I have an Android app I'd like to offer on the Amazon's AppStore. My app has some location-based features and camera features which I need to disable if the user's device is a Kindle. Is there a way to programmatically detect if a user's Device is a Kindle? I'm aware I can build different versions for Kindle and non-Kindle but I thought I'd first ask if there's a way to detect this in code.
To check if the device has a certain feature, you PackageManager.hasSystemFeature(String name) which should be sufficient in your case.
To check for location and camera you can use FEATURE_LOCATION and FEATURE_CAMERA as argument to hasSystemFeature
If you still need to know the hardware of your device, you can check
android.os.Build.MANUFACTURER
android.os.Build.BRAND
android.os.Build.BOARD
android.os.Build.DEVICE
If you want to detect Kindle, check for manufacturer (Amazon) using Build.MANUFACTURER and model using Build.MODEL. The value of model in case of Kindle will vary, it can be KFTT, KFOT, Kindle Fire, etc. See this for model nos.
You can use this method in identifying a Kindle Device(s)
public static boolean isKindle(){
final String AMAZON = "Amazon";
final String KINDLE_FIRE = "Kindle Fire";
return (Build.MANUFACTURER.equals(AMAZON) && Build.MODEL.equals(KINDLE_FIRE) ) || Build.MODEL.startsWith("KF");
}
I know that this post is old, but the approach to this is wrong. If your concern with Kindles is hardware related i.e. Kindles do not have a camera or camera support then you need to check for camera support not device type. What if other devices do not offer camera support? Instead of suggested answer, try this
public static boolean isCameraAvailable(Context context) {
PackageManager packageManager=context.getPackageManager();
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
This is much better than detecting for if device is a kindle, otherwise do another build specific for kindle.

Categories

Resources