I'm trying to make the BroadcastReceiver Run an AlertDialog and it's just skipping the call to the Dialog Method(And throwing into the catch exception):
My BroadcastReceiver:
public void onReceive(Context context, Intent intent) {
this.con = context;
try
{
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "YOUR TAG");
//Acquire the lock
wl.acquire();
intent.getExtras();
new StringBuilder();
wl.release();
String[] a ={"a","b"};
create(context, a); //The Dialog Call
setOnetimeTimer(con);
Toast.makeText(context, "Hurray!", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(context, "Error,broadcastReciver"+e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
And Here is the create() Method:(That Create the Dialog)
public static void create (Context context,String[] descriptions) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(true);
builder.setTitle("Random String");
builder.setMessage(descriptions[rn.nextInt(2)]);
//builder.setMessage("test");
builder.setInverseBackgroundForced(false);
builder.setPositiveButton("Close",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
Thanks!
Edit:Don't say me to put it in an activity and run the activity,because i don't want it to open my app,i want it to be above the opened app.
Without setting the calendar's longer duration fields (e.g., year), it appears that you are setting the alarm before the current time. Try something like this:
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MINUTES, 23*60 + 58);
(Before Edit)1.i Called the class Dialog so when the Intent tried to call to Dialog.class it's called to in System class Dialog.
2.I used:
How do I create a transparent Activity on Android?
to make the Activity Transparent and i used no ContentView so only the Dialog pop-up above the already open activity.
Related
I have tried dismiss the alert dialog when the activity is destroyed.
#Override
public void onDestroy(){
super.onDestroy();
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss();
}
}
But I still got an error:
android.view.WindowLeaked: Activity com.Forewarn.ForewarnApp.activities.SignInActivity has leaked window DecorView#60f300f[] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:424)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.app.Dialog.show(Dialog.java:316)
at com.Forewarn.ForewarnApp.activities.SignInActivity.getFingerPrint(SignInActivity.java:713)
at com.Forewarn.ForewarnApp.activities.SignInActivity$8.onClick(SignInActivity.java:428)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
here is my activity:
if(AccountUtils.getIsTouch().equalsIgnoreCase("true")){
checkTouchId.setChecked(true);
checkTouchId.setVisibility(View.GONE);
txtTouchId.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//Fingerprint API only available on from Android 6.0 (M)
keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
getFingerPrint();
} else {
Toast.makeText(getApplicationContext(),"Your Device does not have a Fingerprint Sensor",Toast.LENGTH_SHORT).show();
}
} else {
getFingerPrintHardware();
}
I'm getting error in below method : in this I'm using two alert dialogs .
public void getFingerPrint(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if(!fingerprintManager.isHardwareDetected()){
/**
* An error message will be displayed if the device does not contain the fingerprint hardware.
* However if you plan to implement a default authentication method,
* you can redirect the user to a default authentication activity from here.
* Example:
* Intent intent = new Intent(this, DefaultAuthenticationActivity.class);
* startActivity(intent);
*/
Toast.makeText(getApplicationContext(),"Your Device does not have a Fingerprint Sensor",Toast.LENGTH_SHORT).show();
//textView.setText("Your Device does not have a Fingerprint Sensor");
} else {
// Checks whether fingerprint permission is set on manifest
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
//textView.setText("Fingerprint authentication permission not enabled");
Toast.makeText(getApplicationContext(),"Fingerprint authentication permission not enabled",Toast.LENGTH_SHORT).show();
} else{
// Check whether at least one fingerprint is registered
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!fingerprintManager.hasEnrolledFingerprints()) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SignInActivity.this,R.style.DialogLevelsStyle);
alertDialogBuilder.setTitle("Touch ID isn't Set Up on This Device");
TextView myMsg = new TextView(this);
myMsg.setText("To set up Touch ID on this decice, go to Settings > Touch id & Passcode and add a valid fingerprint");
myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
myMsg.setPadding(20,50,20,0);
myMsg.setTextColor(getResources().getColor(R.color.colorPrimary));
myMsg.setTextSize(15);
alertDialogBuilder.setView(myMsg);
//alertDialogBuilder.setMessage("Please place your fingertip on the scanner to verify your identity and Login");
alertDialogBuilder.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//finish();
//Toast.makeText(getApplicationContext(),"Hai",Toast.LENGTH_SHORT).show();
startActivityForResult(new Intent(Settings.ACTION_SETTINGS), 0);
}
});
alertDialog = alertDialogBuilder.create();
alertDialog.show();
//textView.setText("Register at least one fingerprint in Settings");
//Toast.makeText(getApplicationContext(),"Register at least one fingerprint in Settings",Toast.LENGTH_SHORT).show();
}else{
// Checks whether lock screen security is enabled or not
if (!keyguardManager.isKeyguardSecure()) {
//textView.setText("Lock screen security not enabled in Settings");
Toast.makeText(getApplicationContext(),"Lock screen security not enabled in Settings",Toast.LENGTH_SHORT).show();
}else{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SignInActivity.this,R.style.DialogLevelsStyle);
alertDialogBuilder.setIcon(R.drawable.fingerprint);
alertDialogBuilder.setTitle("Touch Id for FOREWARN");
TextView myMsg = new TextView(this);
if(hiddenEmail == null){
myMsg.setText("Sign In with User Id "+userName);
}else {
myMsg.setText("Sign In with User Id "+hiddenEmail);
}
myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
myMsg.setPadding(10,50,10,0);
myMsg.setTextColor(getResources().getColor(R.color.colorPrimary));
myMsg.setTextSize(16);
alertDialogBuilder.setView(myMsg);
//alertDialogBuilder.setMessage("Please place your fingertip on the scanner to verify your identity and Login");
alertDialogBuilder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//finish();
Constant.isCanceled = "true";
}
});
alertDialog = alertDialogBuilder.create();
alertDialog.show();
generateKey();
if (cipherInit()) {
FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
FingerprintHandler helper = new FingerprintHandler(this);
helper.startAuth(fingerprintManager, cryptoObject);
}
}
}
}
}
}
}
}
I already added onDestroy method which is calling dailog.dismiss().
I'm confused to find out where I did wrong. Please help me.
leaked window DecorView#60f300f[] that was originally added
Above exceptions are coming if Dialogs are not dismiss() before
Activity is ended.
Add this onPause section.
#Override
public void onPause(){
super.onPause();
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss();
}
}
Rectify
if (cipherInit()) {
FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
FingerprintHandler helper = new FingerprintHandler(this);
helper.startAuth(fingerprintManager, cryptoObject);
}
generateKey();
alertDialog = alertDialogBuilder.create();
alertDialog.show();
Generally, this issue happens when you are trying to show the dialog after your activity is destroyed, finished, onPause, ...
Some solutions:
Check if you are not calling the alertDialog.show(); in the same parent scope where you finish, pause or destroy your activity and try to control it.
for example, you've started another activity or process and then you try to show your dialog on the current activity
You can check if the activity is finished before calling the dialog if(!this.isFinishing()){//show your dialog} this for yourActivity
You can also use a small trick to check the state of your activity before starting a dialog. :
#Override protected void onPause() { isRunning = false; }
#Override protected void onResume() { isRunning = true; }
The broadcast receiver registered for ACTION_USB_DEVICE_DETACHED is working fine, but the same is not working for ACTION_USB_DEVICE_ATTACHED. The thing is that the onReceive() is not called when the intent for ACTION_USB_DEVICE_ATTACHED is fired.
Here is my code where i register the recievers in onCreate()
registerReceiver(mUsbDeviceReceiver, new IntentFilter(
UsbManager.ACTION_USB_DEVICE_DETACHED));
registerReceiver(mUsbDeviceReceiver, new IntentFilter(
UsbManager.ACTION_USB_DEVICE_ATTACHED));
Here is the Code for BroadcastReceiver class:
private final BroadcastReceiver mUsbDeviceReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getBaseContext(), "onRecieve", Toast.LENGTH_SHORT).show();
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
device = (UsbDevice) intent
.getParcelableExtra(UsbManager.EXTRA_DEVICE);
Toast.makeText(
SUSB_Serial.this,
"ACTION_USB_DEVICE_ATTACHED:", Toast.LENGTH_LONG)
.show();
Log.d("dj", "USB attached");
connectUsb();
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
try{
UsbDevice tempDevice = (UsbDevice) intent
.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if(tempDevice != null){
if(tempDevice.getProductId() == device.getProductId()
&& tempDevice.getVendorId() == device.getVendorId()){
Toast.makeText(SUSB_Serial.this,
"ACTION_USB_DEVICE_DETACHED:",
Toast.LENGTH_LONG).show();
Log.d("dj", "USB detached");
AlertDialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(SUSB_Serial.this);
builder.setMessage("Data reading failed, connect back the devices to continue").setTitle("Device Detached!!").
setPositiveButton("Okay", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog = builder.create();
dialog.show();
Log.d("dj", "Releasing resources of USB");
releaseUsb();
}
}
}catch(Exception ex){
Log.d("dj", "Missing device reference");
ex.printStackTrace();
}
}
}
};
This so very simple but i forgot to do so...Here is the answer for which the USB_ATTACHED intent-filter not working from Dev docs.
Also link USB host
Scroll down to the bottom of the page to see the answer
i am trying to implement below code every thing works fine how ever
here is the situation i am facing
mainactivity just has a button to open splashactivity
splash activity does the parsing part then opens the listactvity
my workflow is if user has clicked on the button in main activity
it opens the splash activity and redirects to listactivty the
problem occurs when on the splash activity if a user clicks the
andorid back button it does go back to the mainactivity however the
parsing in splashactivity continues and user is redirected to
listactivty this thing should not happen, when user on splash
activity has clicked backbutton it should go back to mainactivity
and stay there itself
how can this be done
package com.site.name;
public class SplashActivity extends Activity {
RSSFeed feed;
String fileName;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
fileName = "TDRSSFeed.td";
Intent i = getIntent();
int position = i.getExtras().getInt("position");
String[] country = i.getStringArrayExtra("country");
// //public String RSSFEEDURL = "http://blogname.blogspot.com//feeds/posts/default/-/Awards?alt=rss";
Toast.makeText(getApplicationContext(), country[position], Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(), country[position], Toast.LENGTH_SHORT).show();
File feedFile = getBaseContext().getFileStreamPath(fileName);
ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() == null) {
// No connectivity. Check if feed File exists
if (!feedFile.exists()) {
// No connectivity & Feed file doesn't exist: Show alert to exit
// & check for connectivity
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(
"Unable to reach server, \nPlease check your connectivity.")
.setTitle("TD RSS Reader")
.setCancelable(false)
.setPositiveButton("Exit",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
// No connectivty and file exists: Read feed from the File
Toast toast = Toast.makeText(this,
"No connectivity!",
Toast.LENGTH_LONG);
toast.show();
//feed = ReadFeed(fileName);
startLisActivity(feed);
}
} else {
// Connected - Start parsing
new AsyncLoadXMLFeed().execute();
}
}
private void startLisActivity(RSSFeed feed) {
Bundle bundle = new Bundle();
bundle.putSerializable("feed", feed);
// launch List activity
Intent intent = new Intent(SplashActivity.this, ListActivity.class);
intent.putExtras(bundle);
startActivity(intent);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
// kill this activity
finish();
}
private class AsyncLoadXMLFeed extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
// Obtain feed
DOMParser myParser = new DOMParser();
Intent i = getIntent();
int position = i.getExtras().getInt("position");
String[] country = i.getStringArrayExtra("country");
//feed = myParser.parseXml(RSSFEEDURL);
//feed = myParser.parseXml("http://blogname.blogspot.com//feeds/posts/default/-/Awards?alt=rss");
feed = myParser.parseXml("http://blogname.blogspot.com//feeds/posts/default/-/" + country[position] + "?alt=rss");
if (feed != null && feed.getItemCount() > 0)
WriteFeed(feed);
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
startLisActivity(feed);
}
}
// Method to write the feed to the File
private void WriteFeed(RSSFeed data) {
FileOutputStream fOut = null;
ObjectOutputStream osw = null;
try {
fOut = openFileOutput(fileName, MODE_PRIVATE);
osw = new ObjectOutputStream(fOut);
osw.writeObject(data);
osw.flush();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
public void onBackPressed() {
//Include the code here
return;
}
}
You can cancel parsing the feed in MainActivity's onRestart() as this is one method of MainActivity that will be called when you press back from your Parsing Activity.
You can read more about Activity Life Cycle here.
For detecting the Back button press event use the following method
#Override
public void onBackPressed() {
// do something on back.
// Change your activity by calling intent
return;
}
If you want to do anything with your back button then you have to override it manually.
#Override
Public void onBackPressed() {
//do whatever you want to do as your question is quite confusing.
return;
}
public void sendTextMessage1(
final String destinationAddress, final String scAddress, final String text,
final PendingIntent sentIntent, final PendingIntent deliveryIntent){
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
try {
final ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null)
{
if( destinationAddress.length()<10 )
{
new AlertDialog.Builder(null, 0).setTitle("SEND MESSAGE")
.setMessage("Are you sure you want to send this msg to no ? "+ destinationAddress)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with sending
try
{
iccISms.sendText(destinationAddress, scAddress, text, sentIntent, deliveryIntent);
}
catch (RemoteException ex) {
// ignore it
}
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
else
{
try
{
iccISms.sendText(destinationAddress, scAddress, text, sentIntent, deliveryIntent);
}
catch (RemoteException ex) {
// ignore it
}
}
I am following code the Dialog box , but it is not working ,can anyone suggest how to display this
you were passing context reference as null for building alertDialog,pass the context reference otherwise you will experience NPE
change new AlertDialog.Builder(null, 0) to
new AlertDialog.Builder(getApplicationContext(), 0)
This code will works for alert dialog box
public class AlertDialogManager {
/**
* Function to display simple Alert Dialog
* #param context - application context
* #param title - alert dialog title
* #param message - alert message
* #param status - success/failure (used to set icon)
* - pass null if you don't want icon
* */
public void showAlertDialog(Context context, String title, String message,
Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
if(status != null)
// Setting alert dialog icon
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog.show();
}
}
Also u can add this in where u want to set the alert
alert.showAlertDialog(RegisterActivity.this,
"Internet Connection Error",
"Please connect to working Internet connection", false);
i am trying to create alertbox in a thread but getting error here is my code to thread and alertbox ,this alertbox successfully working out of thread.posting code and error logs ,help me.
Thread paypalThread = new Thread() {
#Override
public void run() {
try {
PackageManager pm = getApplicationContext().getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo(
"com.mothistorycheck", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();
Date date = new Date(installed * 1000L);
Date currentDate = Calendar.getInstance().getTime();
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.YEAR, 1);
Date installedPlusYear = cal.getTime();
System.out.println(installedPlusYear);
if (currentDate.compareTo(date)==-1) {
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
.setNegativeButton("Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).create();
// Setting Dialog Title
alertDialog.setTitle("Alert");
// Setting Dialog Message
alertDialog
.setMessage("Either MOT test number or Document Reference Number should be entered!");
alertDialog.setCancelable(true);
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.tick);
// Showing Alert Message
alertDialog.show();
return;
}else
System.out.println("000000");
// int comparison2 = oneYearFromNow.compareTo(date);
// sleep(31536000);
}
catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// finish();
Intent i = new Intent(getApplicationContext(),
SplashActivity.class);
//startActivity(i);
}
}
};
paypalThread.start();
Here log details
10-24 12:32:23.462: E/AndroidRuntime(20705): FATAL EXCEPTION: Thread-5842
10-24 12:32:23.462: E/AndroidRuntime(20705): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-24 12:32:23.462: E/AndroidRuntime(20705): at android.os.Handler.<init>(Handler.java:121)
10-24 12:32:23.462: E/AndroidRuntime(20705): at android.app.Dialog.<init>(Dialog.java:107)
10-24 12:32:23.462: E/AndroidRuntime(20705): at android.app.AlertDialog.<init>(AlertDialog.java:114)
10-24 12:32:23.462: E/AndroidRuntime(20705): at android.app.AlertDialog$Builder.create(AlertDialog.java:913)
10-24 12:32:23.462: E/AndroidRuntime(20705): at com.mothistorycheck.MainActivity$1.run(MainActivity.java:132)
This occur because you can manipulate view inside a thread that is not UI main thread, you can use Handler to perform your dialog appear, also see Handler Example and Handling View inside Handler
You must need to create AlertDialog inside UI thread else it will never work. If you are in different thread use MessageHandler or can use runOnUiThread(using runnable) to create your dialog inside.
Create a handler inside onCreate(), or onResume()
..onCreate(){
...mHandler=new Handler();
}
Then inside your Thread() just use :
mHandler.post(new Runnable{
public void run(){
//Be sure to pass your Activity class, not the Thread
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
//... setup dialog and show
}
});
As already mentioned, you can't make any changes to UI outside of the UI thread. I suggest you use an AsyncTask & create your dialog in onPostExecute callback. this is how you can use it:
public void verifyPaypal() {
PayPalVerifyTask task = new PayPalVerifyTask();
task.execute((Void) null);
}
public class PayPalVerifyTask extends AsyncTask<Void, Void, Boolean> {
#Override
protected Boolean doInBackground(Void... params) {
try {
PackageManager pm = getApplicationContext().getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo(
"com.mothistorycheck", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();
Date date = new Date(installed * 1000L);
Date currentDate = Calendar.getInstance().getTime();
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.YEAR, 1);
Date installedPlusYear = cal.getTime();
System.out.println(installedPlusYear);
if (currentDate.compareTo(date)==-1) {
return true; // this will be passed to onPostExecute
}else
System.out.println("000000");
// int comparison2 = oneYearFromNow.compareTo(date);
// sleep(31536000);
return false;
}
catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// finish();
Intent i = new Intent(getApplicationContext(),
SplashActivity.class);
//startActivity(i);
}
}
#Override
protected void onPostExecute(final Boolean show_alert) {
if (show_alert) {
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
.setNegativeButton("Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).create();
// Setting Dialog Title
alertDialog.setTitle("Alert");
// Setting Dialog Message
alertDialog
.setMessage("Either MOT test number or Document Reference Number should be entered!");
alertDialog.setCancelable(true);
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.tick);
// Showing Alert Message
alertDialog.show();
}
}
}
run verifyPaypal() to start the task.