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 ;)
Related
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.
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()
I have an app that needs to use location services for one of its features. So when the user clicks on a button, I would like my app to check to see whether the device has location services enabled, and if it doesn't prompt the user to enable it via an AlertDialog. When the user clicks the 'Enable Location Services' button, I want the app to take the user to the settings page where the user can enable it.
My problem is that when the user clicks the 'Enable Location Services'
button, instead of opening up the settings page, the app goes straight
into the main activity.
Note: This is all happening inside of a fragment whose parent activity is my second Activity. So here is the layout of my app: MainActivity (login page) => Second Activity (parent activity) => fragment (where this check must occur).
Here is my code inside of the fragment's onCreateView method:
currentLoc.setOnClickListener(new View.OnClickListener() {
DataActivity dataActivity = (DataActivity) getActivity();
Context context = getActivity().getApplicationContext();
#Override
public void onClick(View view) {
if (!dataActivity.isLocationServiceEnabled()){
final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setTitle("Alert");
alertDialog.setMessage("To use this feature, you must first enable location services");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Enable Location Services", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent gpsOptionsIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(gpsOptionsIntent);
}});
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}});
alertDialog.show();
}
else {
AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setTitle("Alert");
alertDialog.setMessage("GPS Enabled...");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
});
Note: currentLoc is an imageView that is created inside the
fragment_layout file
More information:
compileSdkVersion 26
buildToolsVersion "25.0.3"
minSdkVersion 14
targetSdkVersion 26
compile 'com.android.support:appcompat-v7:26+'
compile 'com.android.support:support-v4:26+'
I have tried countless variations that all use intents and for this project they all take me back to the login page (MainActivity). When I create a new project and use the same code, it works...
I have a dialog that prompts users to enable gps location if it's not enabled.
After opening the settings, and the user enableing gps, and pressing the back button from the location settings screen they come back to the app, but the dialog is still visible.
Here is the code for the button clicked.
// On pressing Settings button
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
dialog.dismiss();
}
});
My question is why does the dialog.dismiss() not close the dialog, I have also tried dialog.cancel() with same result. Is there something I should be doing after opening the settings screen?
Thanks,
I have exactly this code in my Activity:
private void showLocationDisabledInfo() {
final Context c = this;
AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.setMessage("TEST");
builder.setPositiveButton("OK", new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
c.startActivity(intent);
}
});
builder.setNeutralButton(R.string.cancel, null);
builder.create().show();
}
and it does close the dialog automatically, no matter what button I click. It's from my application, and it was tested on devices with APIs 8 and 10, and emulator running API 17. The only difference (possibly) between our codes is the value of mContext. Please provide the whole code responsible for setting up the dialog and the environment in which you've seen described behavior.
I have a usecase like repeatedly calling the same dialog box with different values. I am using the same dialog creating code for that. First time the sent data is populated to dialog box. but next time the dialog box not getting rebuilt with different values when i call the same for next time.
Code is here
dialog.setContentView(R.layout.orderdialog);
dialog.setTitle("Selected Item");
dialog.setCanceledOnTouchOutside(true);
System.out.println(selected); // here i am sending different values eachtime. But not updating in dialog.
TextView selectedItem = (TextView)dialog.findViewById(R.id.itemName);
selectedItem.setText(selected);
You can use the android alert builder to show dynamic data:
new AlertDialog.Builder(this)
.setTitle("your title name")
.setMessage("here you can write your dynamic data as string or integer")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(/* don't remember the signature by heart... */) {
// continue with delete
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(/* don't remember the signature by heart... */) {
// do nothing
}
})
.show();
Instead of calling
showDialog(id);
and creating dialog in oncreatDialog function
create the dialog and show it in you on click function itself:
like this:
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("State");
builder.setItems(m_arrStateNames, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
m_nSelStateIdx = which;
showState();
dialog.dismiss();
}
});
builder.show();
}
});