I am working on Amazon FireTV. Is there any API so that i can differentiate whether its a FireTV or FireStick. like
String modal = android.os.Build.Modal;
if(modal.equals(FireTV)){ }else if(modal.equals(FireStick)){ }
Any help will be appreciated.
You can check the Model name:
public String MODELNAME = android.os.Build.MODEL;
public boolean ISFIRETV = MODELNAME.equalsIgnoreCase("AFT*");
public boolean ISFIRETVSTICK = MODELNAME.equalsIgnoreCase("AFTM");
All Fire TV devices have a model name which starts with "AFT":
FireTV (2nd Gen) is "AFTS"
FireTV (1st Gen) is "AFTB"
FireTV Stick is "AFTM".
ISFIRETV can then be used to ensure that it is a FireTV device of any kind (and not for instance sideloaded onto a non-Fire TV device), and then ISFIRETVSTICK can be used to specifically check if it is a FireStick or not.
Besides of answer below there is one more way to check it:
final String AMAZON_FEATURE_FIRE_TV = "amazon.hardware.fire_tv";
if (getPackageManager().hasSystemFeature(AMAZON_FEATURE_FIRE_TV)) {
Log.v(TAG, "Yes, this is a Fire TV device.");
} else {
Log.v(TAG, "No, this is not a Fire TV device.");
}
According to documentation this is the recommended way. But to use it you should have a Context.
Related
How can I differentiate between a TV and a STB/game console on AndroidTV programatically? This method (https://developer.android.com/training/tv/start/hardware) won't work because an STB running AndroidTV is considered a television.
What's Your Goal?
The obvious reason for doing this would be to determine if a device is suitable for a game to be played on. If it's for any other reason, then the purpose needs to be elaborated on in order to receive applicable assistance.
With that said ...
Since it's not possible to query the device type directly -- personally, I'd look for something that only a game console would be likely to have.
In other words: a game controller/gamepad.
public ArrayList<Integer> getGameControllerIds() {
ArrayList<Integer> gameControllerDeviceIds = new ArrayList<Integer>();
int[] deviceIds = InputDevice.getDeviceIds();
for (int deviceId : deviceIds) {
InputDevice dev = InputDevice.getDevice(deviceId);
int sources = dev.getSources();
// Verify that the device has gamepad buttons, control sticks, or both.
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((sources & InputDevice.SOURCE_JOYSTICK)
== InputDevice.SOURCE_JOYSTICK)) {
// This device is a game controller. Store its device ID.
if (!gameControllerDeviceIds.contains(deviceId)) {
gameControllerDeviceIds.add(deviceId);
}
}
}
return gameControllerDeviceIds;
}
Of course, it's not fool-proof. Obviously, nothing would be returned if the gamepad(s) were unplugged at the time (not sure when that would happen). Not to mention, some TVs support gamepads (Samsung comes to mind first) -- but, if you're intention is to verify that there's an adequate input available for the application, this would be ideal.
If a gamepad isn't present, a message could be displayed stating, "Please connect a gamepad." -- while continuously checking in the background, and automatically proceeding once one is detected.
I wrote an android utility that talks to a few custom device over USB using the android UsbHost API. This works fine in 4.4, but in 5.0 some of the devices are missing their interfaces (getInterfaceCount() == 0).
I've been using them on a Galaxy Note 3 with CM11 and they've been working fine, but since this version of CM is unstable I tried to upgrade to CM12. The problem appeared, and I thought it might be a CM bug so I tried a simple program that enumerates devices/interfaces on a Nexus 5 with google's 5.0 release and the problem exists there too.
I created a simple test app with a Button and TextView with an OnClickListener set up as:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_usb);
Button button = (Button) findViewById(R.id.butt);
final TextView text = (TextView) findViewById(R.id.text);
final UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String string = "";
if( manager == null )
string += "no usb manager";
else {
for(UsbDevice device : manager.getDeviceList().values()) {
string += device.toString() + "\n";
string += String.format(" ifc: %d\n", device.getInterfaceCount());
}
}
text.setText(string);
}
});
}
The devices are hooked into a hub which is plugged into the phone with an OTG cable. When this code is run on 5.0, the devices are listed but only one device in the list actually has interfaces (and it is not always the same device). If I shell into the phone with ADB, however, I can see all the devices and their interfaces with 'cat /sys/kernel/debug/usb/devices'.
Is this a bug in android 5.0, or has the usb api changed and I am missing something? I haven't been able to find any information online.
Turns out it is a bug introduced in 5.0. There's an issue on androids bug tracker:
https://code.google.com/p/android/issues/detail?id=159529&q=usb%20interface&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
So it's been known about since 5.0, but currently there has been no work (or even comments) from google about it.
Is there a way to detect this in my Android Application code ?
I want to differentiate "Box type" (e.g. NSZGS7, without display attached) and built-into-TV type (NSXGT1, with display) googleTV devices. Is there a standard system property or feature flag that I can use for this differentiation ?
I don't think there is a super elegant way to detect if a device has a display or if it's a box. But you can use android.os.Build to detect Manufacturer/Device/Model etc and differentiate based on the system properties.
http://developer.android.com/reference/android/os/Build.html
Here are the system properties for most of the currently available GTV devices:
MANUFACTURER DEVICE MODEL
Sony NSX-GT1(TV) Sony asura Internet TV
Sony NSZ-GT1(BD) Sony eagle Internet TV Box
Sony NSZ-GS7(Box) Sony NSZGS7 NSZ-GS7/GX70
Sony NSZ-GU1(Stick) Sony NSZGU1 NSZ-GU1
Logitech Revue(Box) logitech ka Revue
Netgear GTV100(Box) Netgear NeoTV GTV100
Hisense Pulse(Box) hisense hisense_gx1200v hisense_gx1200v
Vizio Costar (Box) VIZIO VAP430 VAP430
LG G2(TV) lge cosmo LG Google TV
Hope this helps! -Tonni from Sony
This is the code I am using for now. It is not future proof, meaning this code will need to be updated as new TV type GoogleTV devices are released. However, this code gets the job done for now.
boolean is_gtv_device_type_tv(){
if (context.getPackageManager().hasSystemFeature("com.google.android.tv")) {
if(android.os.Build.DEVICE != null) {
if(android.os.Build.DEVICE.equalsIgnoreCase("asura"))
return true;
if(android.os.Build.DEVICE.equalsIgnoreCase("cosmo"))
return true;
}
// All other google tv devices are buddy boxes!! :)
return false;
}
}
Look for ro.hdmi.device_type in "device properties" (For HDMI sink devices, like panel TVs it's "0", for HDMI source devices, like Over the Top (OTT) boxes it's "4").
Using ABD:
adb shell getprop ro.hdmi.device_type
Programmatically:
public static String getDeviceType() {
switch (System.getProperty("ro.hdmi.device_type")){
case "0":
return "TV";
case "4":
return "BOX";
default:
return "UNKNOWN";
}
}
I am developing a Google Play services based app. I am using the suggested BaseGameActivity superclass to inherit lots of the functionality. The user can log in via their Google account.
I wanted to provide a special preference setting for testers of the android app.
After looking in the SDK reference,
I haven't been able to find if there is any way to determine whether the logged in user is configured as a tester for the app. Is this possible?
Is there another recommended way to provide extra functionality for testers of the app related to their testing? For instance, in my game app, I want to allow the testers to reset their achievements and leaderboard entries, which I found can be done via a web service call.
Thanks
There's no such API that I know of.
The trick that I have been using, and you are welcome to use as well is to
determine whether a device is a tester device by its ANDROID_ID, and fork different
behaviors accordingly. Something like this:
static String androidId;
static boolean isTesterDevice;
boolean isTesterDevice() {
if (androidId != null) {
return isTesterDevice; // optimization: run string compares only once
}
androidId = Secure.getString(context.getContentResolver(),Secure.ANDROID_ID);
isTesterDevice = Arrays.asList(ALL_TESTER_DEVICES).contains(androidId);
return isTesterDevice;
}
Where ALL_TESTER_DEVICES is a String array containing all testers ANDROID_IDs:
static final String[] ALL_TESTER_DEVICES = {
"46ba345347f7909d",
"46b345j327f7909d" ... };
Once we have this working we can create tester specific logics inside our code:
if (isTesterDevice()) {
perform tester logic
}
We can also pass a isTester field to the backend server as part of the handshake
procedure, allowing it to perform its own set of tester handling.
This works just fine for small teams of testers. When QA teams grows larger, or
when you cannot ingerrogate some of the tester devices for their ID, we find it
useful to allow our testers to flag their identity by adding a special file to
the SDCARD. In that case isTesterDevice() will change to:
boolean isTesterDevice() {
if (androidId != null) {
return isTesterDevice; // optimization: run string compares only once
}
// check by device ID
androidId = Secure.getString(context.getContentResolver(),Secure.ANDROID_ID);
isTesterDevice = Arrays.asList(ALL_TESTER_DEVICES).contains(androidId);
if (!isTesterDevice) {
// check by tester file
File sdcard = Environment.getExternalStorageDirectory();
File testerFile = new File(sdcard.getAbsolutePath(), "I_AM_TESTER.txt");
isTesterDevice = testerFile.exists();
}
return isTesterDevice;
}
Hope it helps.
I want to find device specification of a mobile phone for examples, the device manufacturer, model no ( and may be types of sensors in the device, wifi chipset etc..). I want to get the device manufacture/model number (eg. Samsung GT-I9100 i.e Galaxy S2) programmatically. The manufacture/model number is also used in Google Play when installing an app. I want to use this information to make some configuration changes in my hardware dependent app (for eg. power measurement).
You can get as below:
String deviceName = android.os.Build.MODEL;
String deviceMan = android.os.Build.MANUFACTURER;
For more other device details, Please refer this document: android.os.Build
I just wanna elaborate on how to use the built in Attribute for the future visitors. 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");
}
String deviceName = android.os.Build.MODEL;
String deviceMan = android.os.Build.MANUFACTURER;
The original solution will work fine, however it will not detect a custom ROM (non OEM) in call cases. You may want to also evaluate the android.os.Build.PRODUCT string or other strings from the Build class.
String build = android.os.Build.PRODUCT;