how to click AlertDialog NegativeButton in python Appium api? - android

I am a fresh in Appium. I use this code to show permission alert and I want to test it.
new AlertDialog.Builder(activity).setTitle("ALERT")
.setMessage(reason)
.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
ActivityCompat.requestPermissions(activity,new String[]{permissionType},requestCode);
}
}).create().show();
I use appium desktop and python appium-client ,how to wait until this alert dialog show and then catch this NegativeButton and click it?

driver.switch_to_alert().accept() can work.
it is Deprecated use driver.switch_to.alert.
driver.switch_to.alert.accept() can work.

Related

How would I make a basic alert?

I have a if then statement. If the if then statement is true, I want an Android system to fire a basic alert with one button that says ok.
I have done plenty of research, but nothing works.
this is how you create Alert in android
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Write your message here.");
builder.setNeutralButton(
"Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.create().show()

Android Toast text on next activity

I have an intent and I want a toast to show as soon as we get to that intent. Code:
Toast.makeText(this,"Please enable internet connection",Toast.LENGTH_LONG).show;
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
As you can see im going to the android setting, and I want it to prompt them to activate WiFi. Any ideas or better ways to do this?
I would rather recommend to show a dialog which asks the user to enable the wifi connection for him and then call WifiManager.setWifiEnabled() to switch on wifi.
This way, you don't have to leave your app. It is not possible to show an toast from an external activity.
Quick alternate approach:
Don't show a toast. Display a dialog saying "Please enable internet connection" and when the user presses the "OK" button fire the intent to send him to the settings page.
You could use a dialog, here's an example
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("WiFi Settings");
builder.setMessage("Please enable internet connection");
builder.setCancelable(false);
builder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
// Launch settings activity
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)););
}
});
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
}
});
builder.create().show();

Showing app updation Dialog Box every time whenever user opens the app

I am using AppUpdater library for Android to notify the user through a dialog box that a new version is avaliable.
All i want that everytime user opens the app dialog box will appear every time until user update to latest version.
AppUpdater appUpdater = new AppUpdater(this)
.setDisplay(Display.DIALOG)
.setUpdateFrom(UpdateFrom.XML)
.setUpdateXML("https://firebasestorage.googleapis.com/v0/b/sensortest-7881e.appspot.com/o/appupdater.xml?alt=media&token=c75bd1f6-5d65-4414-9199-26ab05f7d0f2")
.showEvery(5)
.setTitleOnUpdateAvailable("Update Avaliable")
.setContentOnUpdateAvailable("Check out the latest version available")
.setButtonUpdate("Update now")
.setButtonUpdateClickListener(new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"Update Button Clicked",Toast.LENGTH_LONG).show();
}
})
.setButtonDismiss("Maybe later")
.setButtonDismissClickListener(new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//dialog.dismiss();
Toast.makeText(MainActivity.this,"Maybe Latter",Toast.LENGTH_LONG).show();
}
})
.setButtonDoNotShowAgain(null)
.setIcon(R.drawable.ic_system_update_white_24dp)
.setCancelable(false);
appUpdater.start();
Put your code inside a function like:
public void checkForUpdates(){
AppUpdater appUpdater = new AppUpdater(this)
.setDisplay(Display.DIALOG)
.setUpdateFrom(UpdateFrom.XML)
.... .... .. .. ... .. .
}
Then call checkForUpdates(); on the "OnResume" method, and it will work ;)

My neutral Ok button is not showing in my alert dialog for Samsung S5 and J700

Trying to build a mobile application and have tested across some devices, but when it comes to Samsung S5 Notebook and J700 mobile phones, both have been failing because they have failed to display the neutral button in the application, please who might have the slightest clue to solving this particular issue. Thanks.
Here is a sample code below;
new AlertDialog.Builder(context)//new Alert Dialog
.setTitle("Delete entry")//set title
.setMessage("Are you sure you want to delete this entry?")
.setNeutralButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})`enter code here`
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
just replace with this -
AlertDialog.Builder builder = new AlertDialog.Builder(context)//new Alert Dialog
.setTitle("Delete entry")//set title
.setMessage("Are you sure you want to delete this entry?")
.setNeutralButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setIcon(android.R.drawable.ic_dialog_alert);
// .show();
AlertDialog d = builder.create();
d.show();
Maybe you should try with .setPositiveButton this should work.
Check if you are using AlertDialog from support library?

Video call got disconnect due to do not keep activities check in android device

ongoing video call got disconnected when it goes to on pause because of do not keep activities checked under developer option in android device how can a user stay in video instead of that option is checked
You can check "Is the do not keep activities is checked or not" by using below line,
int value = Settings.System.getInt(getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0);
If it returns one, create a AlertDialog and ask the user to disable it first, if user clicks on positive button then create an intent for the Settings like below,
int value = Settings.System.getInt(getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0);
if (value == 1)
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("");
// set dialog message
alertDialogBuilder
.setMessage("You need to disable `do not keep activities` option, press YES")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.dismiss();
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
I am entirely not sure if I got you correctly.
But does this: https://developer.android.com/training/scheduling/wakelock.html
answer your question?
It prevents your app from entering onPause, when a voice-chat is ongoing.

Categories

Resources