I am setting up the Android Device Buttons to work with my app. According to the PG/Cordova documentation I should be able to just add an listener such as
document.addEventListener("backbutton", function() {
console.log('Back Button Pressed.');
}, false);
However, when using my Nexus 7 as a test device, nothing happens.
I have also tried adding the override directly into Java:
#Override
public void onBackPressed() {
super.loadUrl("javascript:onBackKeyDown()");
return;
}
But once again, seems to do nothing. Anyone else having this issue or fixed?
Thank you.
First of all, ur function write into the console.
document.addEventListener("backbutton", function() {
console.log('Back Button Pressed.');
}, false);
You should set your device as debugging tools (, you will find below a quick hint how to do it, for more info go here )
Connect your phone to the pc
On your phone: check USB debugging;
setting => Developer Option => USB debugging
On your phone: check unknown sources;
settings >> applications >> unknown sources = true
add your device to the ADT (in your SDK)
run the project directly from the pc to the mobile :
right-click on the project => Run AS => choose your device
NOW on Back button Click, "Back Button Pressed." will be printed in the console of Eclipse.
If your device is not connected to the Computer or if your device is not set as debugging tools, Nothing will change.
In General case Use "alert()" in stead of "console.log()" if you are testing on the device without setting it as debugging tools.
Beside, dont use the native java, use the original documentation of Cordova, just add the following code into your javascript files:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// Cordova is loaded and it is now safe to call Cordova methods
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the back button
//
function onBackKeyDown() {
// whatever you want to do
alert('Back button Pressed');
}
then you should add "onLoad()" to the body tag:
<body onLoad="onLoad()">
Related
So all I want to do is clicking on dialog that only pops up on the iOS Simulator (iOS 14.5, Appium Java-Client 7.3.0).
The dialog comes from Anyline because of course I have no camera on the simulator.
If there is any way to hide this dialog it would solve my problem too, I tried this with capabilities but it doesn't worked.
cap.setCapability("autoAcceptAlerts", false);
cap.setCapability("autoDismissAlerts", false);
Selecting the dialog is no problem, i can check that the Dialog is here:
#iOSXCUITFindBy(accessibility = "Anyline SDK cutout UI")
public IOSElement anylineDialog;
This is how it looks like:
So the next step would be to just click the ok button it worked at the beginning but now I can't even select it in the Appium Inspector anymore. Before I just used this:
#iOSXCUITFindBy(accessibility = "OK")
public IOSElement okButton;
I don't know why it doens't work anymore, but I can still select it with the help of TestProject.
I tested a lot of different selectors but it doesn't worked. (the one with accessibility = "OK" is also recommended in this tool)
I always get this exception and I don't know how to fix it, try catch also doesn't work:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
I tried out the stuff on this page and I also get the OK button as the only button as this code snippet shows.
HashMap<String, String> args = new HashMap<>();
args.put("action", "getButtons");
List<String> buttons = (List<String>)driver.executeScript("mobile: alert", args);
Also from the same site, I tried this with the same result.
args.put("action", "accept");
args.put("buttonLabel", "OK");
driver.executeScript("mobile: alert", args);
Maybe this is to specific but if someone has an idea how I could solve it, I would be very thankful.
The iOS bug you mentioned has been fixed in Appium 1.22.1 and 2.0.0-beta. Be sure you are running one of those versions and you should be fine.
I am working on stripe-terminal-android-app, to connect to BBPOS 2X Reader device,
wanted to click-item from list,(recyclerView).
I am trying to do:
when list of devices appears(readers), I am checking if readers.size()==1, then click first-device from list,else show recyclerView();
I have very less experience in Android(coming from JS, PY), :)
After going through debugger to understand flow of program-running, I used F8 key, or stepOver the functions one by one,
and where value is assigned to convert in displayble-format in adapter as here.
public ReaderAdapter(#NotNull DiscoveryViewModel viewModel) {
super();
this.viewModel = viewModel;
if (viewModel.readers.getValue() == null) {
readers = new ArrayList<>();
} else {
readers = viewModel.readers.getValue();
if(readers.size() == 1){
Log.e(TAG, "readers.size() is 1 "+ readers.size());
}
}
}
then in ReaderHolder-file, values are bind() as
void bind(#NotNull Reader reader) {
binding.setItem(reader);
binding.setHandler(clickListener);
binding.executePendingBindings();
}
}
I tried assigining button and manually clicking when only-one device appears, by clicing on reader[0], can't do that by findViewById inside Adapter file, to call onClick() method manually,
I tired another StackOverflow's answer but didn't understood, from here.
Main fragment is discovery-fragment,
how can I click first-device by checking readers.size()==1, then click onClick()?
my final-goal is to automate, whole stripe-terminal-payment process on android.
extra-info:
I am fetching data from python-odoo server, then using url, will open app through browser, (done this part), then device will be selected automatically as everytime-no any devices will be present except one,
so will automatically select that from recyclerView, then proceed.
I have asked for help in detailed way on GitHub-issues, and started learning Android's concepts for this app(by customizing stripe's demo app, which works great, but I wanted to avoid manually clicking/selection of devices).
I need to simulate home button click in Espresso on Android phone.
I tried
onView(withId(android.R.id.home)).perform(click());
and onView(withContentDescription("Navigate up")).perform(click());
as some posts suggested but it always fails to find the view.
I'm new to Espresso and not sure how to debug it. Thanks.
Better to use withContentDescription(R.string.abc_action_bar_up_description) rather than "Navigate up" but it doesn't act like a home button click anyway, it only uses the navigation bar's "back" button, so it would only work if you have it in your app.
If you want to simulate the home button click and you are using the UI Automator library, you can simulate it like this
fun pressHome() {
// Might be a good idea to initialize it somewhere else
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
uiDevice.pressHome()
}
Alternatively, if you don't want to or can't use UI Automator, you might try calling Intrstumentation.sendKeyDownUpSync() with the KeyEvent.KEYCODE_HOME.
I work with PhoneGap and I try to denied user from go page when using back button in mobile I search I found this code
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var snd = new Media("/android_asset/www/sfx/lbl.ogg");
snd.play();
document.addEventListener("backbutton", function (e) {
e.preventDefault();
}, false);
}
Also I would like to run ogg music on enter the appliction but it's not work both of them not work.
1.Android ogg files supported latest version only refer this confirm this ....
2.Change file format of audio file and run.
3.Then put your back key Listener inside ondeviceReady
document.addEventListener("backbutton", onBackKeyDown, false);
and write function on for onBackKeyDown
I have an android app that uses the permission "CALL_PHONE". This simple app would just contain a button that would use the call intent to call a specific number. I would like to install this app on both tablets and phone but when it is installed on the tablet, I would like the button to be disabled during runtime so errors wouldn't show when the user tries to call using the tablet without a call function.
At the moment, I am using the setEnabled() and setClickable() method in my MainActivity.java and setting it to false when the user clicks on the button the first time. My question is whether the button can be disabled and the text changed during runtime or when the app is first opened (in a tablet) so the user wouldn't have to click the button first for it to show that the "call" button should be disabled and unclickable?
Refer to this
That will help you in identifying that your application is running on tablet. Now as for disabling your button, I would suggest something like this:
onCreate()
{
setContentView(R.layout.main);
boolean isTablet = checkDevice();
callBtn = (Button) findViewById(R.id.call);
if (isTablet)
{
callBtn.setEnabled(false);
callBtn.setText("Not allowed to make a call");
}
callBtn.setOnClickListener( new onClickListener(){
//Make a call
});
}
public boolean isTablet()
{
//Code for identifying. Return true if application is running on tablet
//return false otherwise
}
So you won't have to wait for user's click on Call button to disable it in tablet.
Hope that helps.
Use button.setEnabled(false); to make visible but user cant click and
button.setVisibility(View.GONE); to make button invisible.and button.setText("YOUR_NEW_TEXT"); to change the button text runtime
And this is not depend on the size of the screen.
Is this you wanted?? OR be more specific with your queston.
... the text changed during runtime?
You can use the setText(); method.
About the other part of your question, you need first to define "What is a tablet?". Is it a 7", 8", 10" screen? Is it a mdpi, hdpi, xhdpi screen? Is it a device which is able to do phone calls? What is a tablet for you or your project? Depending on your answer, you can filter your code (or xml in folders) to make them work the way you want.