Android SDK, Check if device is Amazon-FireTV - java

I am trying to write a simple piece of code that will execute some other code if true. What I want to do is check if my app is running on the 'Amazon Fire-TV (BOX, not the Fire-TV stick)' I think it would not be that hard to do but I am guessing it would be something like this?
String osName = android.getSystemOS();
if(!osName.equals("AMAZON FIRE-TV")){
Toast.makeText(MainActivity.class, "This app may not be compatible with your device..., Toast.LENGTH_LONG").show();
...
}

You can check any device name specifically using:
boolean isFireTV = Build.MODEL.equalsIgnoreCase("AFTB");
(see this page for FireTV model strings, and this one for Fire Tablets)
I'd also check out this answer for a more generic test to help you determine if your app is running on an Amazond device, or installed via the Amazon AppStore (eg on a Blackberry device)

the following function:
public static boolean isTV() {
return android.os.Build.MODEL.contains("AFT");
}
should detect either firetv or fire tv stick
see
https://developer.amazon.com/public/solutions/devices/fire-tv/docs/amazon-fire-tv-sdk-frequently-asked-questions
for details

Related

Calling the voice-input feature - CodenameOne app (iOS port)

My Android app features a text input box that has a button on the right of the EditText to call the voice-input feature.
I am porting the app with Codename One. At present time the iOS port is the goal.
The button has a suitable icon. This is the code:
voiceInputButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
try {
activity.startActivityForResult(voiceIntent, RESULT_SPEECH_REQUEST_CODE);
} catch (ActivityNotFoundException ex) {
}
}
});
It works very well, the voice-input screen is called and then the result is passed back to the app as a string.
The string is what the user said (for example, a single word).
I need to have this functionality in the CodenameOne app for iOS.
What should be the equivalent? Is it necessary to call native iOS functions, through the native interface?
You can implement speech-to-text via Speech framework, to perform speech recognition on live or prerecorded audio. More info: https://developer.apple.com/documentation/speech
About Codename One, you can create a native interface using Objective-C code.
To use the Speech framework with Objective-C, see this answer:
https://stackoverflow.com/a/43834120
The answer says so: «[...] To get this running and test it you just need a very basic UI, just create an UIButton and assign the microPhoneTapped action to it, when pressed the app should start listening and logging everything that it hears through the microphone to the console (in the sample code NSLog is the only thing receiving the text). It should stop the recording when pressed again. [...]». This seems very close to what you asked.
Obviously the creation of the native interface takes time. For further help, you can ask more specific questions, I hope I have given you a useful indication.
Lastly, there are also alternative solutions, again in Objective-C, such as: https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/objectivec/ios/from-microphone
You can search on the web for: objective-c speech-to-text

Unity AndroidJavaObject not working without showing errors

I have been trying to call a Java method in unity. Not working for me, even the simplest example from the docs
using System.Collections;
using UnityEngine;
public class ExampleClass : MonoBehaviour {
void Start () {
AndroidJavaObject jo = new AndroidJavaObject ("java.lang.String", "some string");
int hash = jo.Call<int> ("hashCode");
Debug.Log ("hash=" + hash);
}
}
Unity console prints hash=0, which is not the hash code for provided String. Even if I change and use java.lang.StringInvalidClass as class name, unity still reports same result to the console without notifying errors. I can even try to call toString, toStringa, toInvalid2 and they always return empty string without showing errors.
This is a brand new 2d project with only script displayed above, attached to camara object. I am using Ubuntu, Unity 2019.4 and project platform is Android.
Thanks for the assistance.
Answering myself after some time working with unity.
All examples in the web and unity documentation doesn't mention it, which is weird since it is something simple to mention and about confusions: code needs to run as an android application. Editor or even unity remote does not work, in order to use AndroidJavaObject and related classes, your code needs to run as an android application installed in the phone.

What command do I use to fix this problem?

My main goal is to create a program that can automate an android app to do everything you would with your fingers.
I wrote this line of code so that if that switch is turned ON, the code will switch it OFF.
driver.findElement(By.id("com.offerup:id/shipping_checkbox")).click();
But when I run my code again, that switch is now OFF by default.
I need a command that leaves the switch alone if it is already OFF.
Does anyone know what command to use?
You need to check whether the switch is ON or not. You could achieve this using the following code:
if(driver.findElement(By.id("com.offerup:id/shipping_checkbox")).isSelected()){
driver.findElement(By.id("com.offerup:id/shipping_checkbox")).click();
}
Updated:
As mentioned by Muzammil, isSelected() is not working as expected. Alternatively, you could use the checked attribute:
MobileElement shippingCheckbox= driver.findElement(By.id("com.offerup:id/shipping_checkbox"));
if(shippingCheckbox.getAttribute("checked").equalsIgnoreCase("true")){
shippingCheckbox.click();
}
There are 2 ways to check slider is on or off.
This is Node details of Slider.
Option-1: By using text
Here we will click only if slider is On.
MobileElement sliderElement=driver.findElement(By.id("com.offerup:id/shipping_checkbox"));
String sliderStatus = sliderElement.getText();
if (sliderStatus.equalsIgnoreCase("On")) {
sliderElement.click();
}
Option-2: By using Attribute
Here we will click only if slider is On.
MobileElement sliderElement=driver.findElement(By.id("com.offerup:id/shipping_checkbox"));
String sliderStatus=sliderElement.getAttribute("checked");
if (sliderStatus.equalsIgnoreCase("true")) {
sliderElement.click();
}
}
Edit: I made a mistake in reading this, and missed that it was an Android app, so Javascript is likely unavailable. This comment will only help someone with the same issue on web browser testing, or any situation where Javascript can be executed on the application.
Additional possibility for checking. Not that it is superior to other options.
using OpenQA.Selenium.Support.Extensions;
string selector = "com.offerup:id/shipping_checkbox";
if(driver.ExecuteJavascript<bool>($"return document.getElementById('{selector}').checked")) {
driver.findElement(By.id($"{selector}")).click();
}

How can I play Alert.startAudio() through the phone speaker?

I need to play Alert.startAudio() through the loudspeaker of a Blackberry device instead of the headset.
I know that I can change the Audio path through the AudioPathControl interface, but I don't know how to get an instance of AudioPathControl.
I found a LINK on how to do it on the Blackberry Knowledge base, but it only tells me how to do it using the Player class, which I don't want to do. Is there any way to get an instance of AudioPathControl of the current Application?
I would prefer to play a tone programmatically instead of including my own sound file. I found the following code snippet for that.
Player p = javax.microedition.media.Manager.createPlayer(javax.microedition.media.Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl tc = (ToneControl) p.getControl("ToneControl");
AudioPathControl apc = (AudioPathControl) p
.getControl("AudioPathControl");
apc.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSFREE);
tc.setSequence(mySequence);
p.start();
But the problem is that apc is null and throws an Exception. Any solution?
Check the section Where Does the Sound Go? (preview from Google Books), from Advanced BlackBerry 6 Development By Chris King.

How to know if I am running in an emulator or real mobile phone

I would to like to know if Is there any to check if I am running the application in a emulator or real phone? I want to change some configuration when I am testing in the netbeans/emulador and when it goes to real mobile phone change to another configuration such as server address. Is there any java me function to check it?
You have to use this code.
String platform = System.getProperty("microedition.platform");
platform = platform.toUpperCase();
if ((platform.indexOf("J2ME") != -1) || (platform.equalsIgnoreCase("SunMicrosystems_wtk"))) {
//EMULATOR
}else {
//Device
}
If you are using other emulator you can try doing System.out.println(platform) and see what print when yo are using on emulator
You can add a property in JAD, and just change that property when you build for real device
for example :
device-name: emulator
and you can read it in MIDlet using
getAppProperty("device-name");

Categories