How to customize the Uninstall alert Dialog? - java

I'm developing an android application .In that app , I wanna uninstall an application my app .
I've used the following snippets ,
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:" + ((ResolveInfo)list.get(position)).activityInfo.packageName));
c.startActivity(intent);
The uninstall alert is opened and uninstalling done fine .But I want to customize the uninstall alert dialog . How to do that ?

Can be try from this code...............................
public void btFirst(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
// set title
alertDialogBuilder.setTitle("ALERT>>>>>");
// set dialog message
alertDialogBuilder
.setMessage("UNINSTALL")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
Uri packageURI = Uri.parse("package:com.example.pp");
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(intent);
//MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}

Related

android: Position AlertDialog.Builder below toolbar so that NavigationDrawer is clickable even when AlertDialog is showing

I have an AlertDialog.Builder but the problem is that when the AlertDialog.Builder is showing I am unable to click on the toolbar becase AlertDialog.Builder is drawn above all other views.. how do I make this AlertDialog.Builder not cancel able but still be able to click on toolbar items.
here is a snapshot for a better understanding
HERE IS MY CODE:
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
//Set title
builder.setTitle("Approval Pending")
//Set message
.setMessage("Your account with Reference Id [" + jObj0.getString("reference_id") + "] is in Pending state.")
.setNegativeButton("REFRESH", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(Utils.isConnected(getContext())) {
dialog.dismiss();
fetchdashboardfragmentdata(true);
}else{
builder.show();
Toast.makeText(getContext(), "Please turn on your Internet connection and try again", Toast.LENGTH_SHORT).show();
}
}
})
.setPositiveButton("LOGOUT", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
StoreSharePreference.SSP().logout(getContext());
Intent intent = new Intent(getContext(), Login_Page.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
getActivity().finish();
}
})
.setOnKeyListener(new DialogInterface.OnKeyListener() {
#Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
}
return false;
}
})
.setCancelable(false);
AlertDialog alert = builder.create();
alert.show();
--I want to be able to click on cart icon, wishist icon and navigation drawer when the AlertDialog.Builder is showing.--
you can't touch element behind an alert dialog, because dialog always overlaying your activity. you have to dismiss the dialog before touching the activity UI components.
you can do this by using
AlertDialog helpDialog = alert.create();
Window window = helpDialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);

How to Create A "Do you want to Continue?" Alert Box

In my application I have a button that when pressed I want it to display an Alert Dialog Box that asks if you want to continue. It will have two buttons: a "Continue" and "Do Not Continue". I am putting the method that opens up the dialog box within the method that opens the new Activity like so:
case R.id.bRegister:
try{
//the method for opening the alert box goes somewhere here but i don't know where yet.
Class ourClass = Class.forName("org.health.blablablabla.app.RegisterData");
Intent ourIntent = new Intent(MainActivity.this,ourClass);
finish();
startActivity(ourIntent);
overridePendingTransition(R.animator.fadein,R.animator.fadeout);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
This is currently what I have for the Alert Dialog Box method:
private void showWarning(){
AlertDialog.Builder warning = new AlertDialog.Builder(this);
warning.setTitle("Existing Data");
warning.setMessage("There is already existing data. If you continue all previous data will be deleted. Are you sure you want to continue?");
warning.setPositiveButton("Continue",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1)
{
arg0.dismiss();
}
});
warning.setNegativeButton("Do Not Continue",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
});
}
My question is where to put the method in the first block of code, and how do I make it so that when the "Do Not Continue" button is pressed, the New Activity "RegisterData" doesn't open up.
you can make an YesNoSampleActivity and use AlertDialog.Builder like this:
public class YesNoSampleActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Put up the Yes/No message box
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle("Erase hard drive")
.setMessage("Are you sure?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Yes button clicked, do something
Toast.makeText(YesNoSampleActivity.this, "Yes button pressed",
Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No", null) //Do nothing on no
.show();
// Continue code after the Yes/No dialog
// ....
}
}

alert box in android is not working

The code is not working. Please help me. It print the replace all string, but further code is not running.
when I debug this, there is no error in the code. It will show the code of alert box.
if(count>0)
{
System.out.println("replace all string name ");
// final Intent intent_ul=new Intent(this, UploadExcel.class);
AlertDialog.Builder alertDialogBuilder_ue = new AlertDialog.Builder(this);
alertDialogBuilder_ue.setTitle("Alert!!");
alertDialogBuilder_ue
.setMessage("Are you sure you want to Replace all the data related to this style ? ")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
mySQLiteAdapter.openToWrite();
mySQLiteAdapter.delete_style_measurement(style_no);
Log.d("","yes click");
count=0;
mySQLiteAdapter.close();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
Log.d("","No click");
count++;
dialog.cancel();
// startActivity(intent_ul);
//finish();
}
});
}
Add these lines before the end of if condition
AlertDialog alertDialog = alertDialogBuilder_ue.create();
alertDialog.show();
You need to add
alertDialogBuilder_ue.show();
in your code
Check with this code. This code working for me
Context context = CurrentActivity.this;
AlertDialog.Builder ad = new AlertDialog.Builder(context);
ad.setTitle("Application");
ad.setMessage("Do you want to proceed?");
ad.setPositiveButton("Yes", new OnClickListener()
{
public void onClick(DialogInterface dialog, int arg1)
{
}
});
ad.setNegativeButton("Cancel", new OnClickListener()
{
public void onClick(DialogInterface dialog, int arg1)
{
}
});
ad.setCancelable(false);
ad.show();
In your code adding alertDialogBuilder_ue.show(); should make the dialog appear.
By some people it has been suggested that you have to use alertDialogBuilder_ue.create(); to get a handle to the AlertDialog that you can then use the .show() method on.
Both are possibilities but you don't have to use the .create() option if you don't need a handle to the AlertDialog

Android AlertDialog how to block second click on the ok button?

Example:
System.out.println("in!");
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("test!!!");
dialog.setPositiveButton(R.string.dialog_ok,
new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.out.println("Only one click!");
}
});
dialog.show();
Out:
in!
in!
Only one click!
Only one click!
Only one click!
Only one click!
Get the button (positive) and set enabled to false.
System.out.println("in!");
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("test!!!");
dialog.setPositiveButton(R.string.dialog_ok,
new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// disable on 1st click;
final AlertDialog alertDialog = (AlertDialog)dialog;
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
System.out.println("Only one click!");
}
});
dialog.show();
What i don't understand is why someone could click a second time on an alertdialog, because teh buttons are supposed to close the dialog after performing some action.
Why do you not close the dialog with
dialog.dismiss()
?
You need to disable it. I recommend a flag, which must be stored at the class level.
Boolean hasBeenClicked=false;
System.out.println("in!");
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("test!!!");
dialog.setPositiveButton(R.string.dialog_ok,
new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (!hasBeenClicked)
{
hasBeenClicked=true;
System.out.println("Only one click!");
}
}
});
dialog.show();

Alert Dialog Icon Won't Set

I have a 14x14 png file (icon_alert.png) in my drawable-hdpi folder. This is how I am setting the icon:
alertDialog.setIcon(R.drawable.icon_alert);
The icon is not there when the dialog is shown.
You need a title too, otherwise it won't work.
public class ExampleApp extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("Do you want to close this window ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Title");
// Icon for AlertDialog
alert.setIcon(R.drawable.icon);
alert.show();
}
}
You can use alertDialog.setIcon(R.drawable.icon);
The icon must be either .png or .jpg, I would highly recommend 16X16.

Categories