I get push notifications, using this message create a Dialog to get the availability. Here I get push notification in Dialog form if the app is already open, if the app is not open, push notification comes and Dialog is not coming, How may I get the Dialog even the app is not open. Here is my Code.
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
String[] msg = newMessage.split(",");
latitude = Double.parseDouble(msg[0]);
longitude = Double.parseDouble(msg[1]);
glat = msg[0];
glon = msg[1];
ambNo = msg[3];
currIncId = msg[4];
// Waking up mobile if it is sleeping
WakeLocker.acquire(getApplicationContext());
if(newMessage!=null)
{
showAlertDialog(context, msg[2]+" AT", getMyLocationAddress(latitude, longitude), false);
return;
}
WakeLocker.release();
}
};
and this is my Dialog Code:
public void showAlertDialog(final Context context, String title, String message,
Boolean status)
{
dist = String.valueOf(distanceFrom(lat, lon, latitude, longitude));
Log.i("DISTANCE TO MES FOM AMB", dist);
final GPSTracker gps = new GPSTracker(context);
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setCancelable(false);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("RESPOND", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params){
stat = ServerUtilities.updatestatus(context, ambNo, String.valueOf(gps.getLatitude()), String.valueOf(gps.getLongitude()), "1", currIncId);
return null;
}
@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}
};
mRegisterTask.execute(null, null, null);
Intent mrAc = new Intent(context,MapRouteActivity.class);
startActivity(mrAc);
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("DECLINE", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ServerUtilities.updatestatus(context, MainActivity.ambNo, MainActivity.glat, MainActivity.glon, "0",MainActivity.currIncId);
return null;
}
@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}
};
mRegisterTask.execute(null, null, null);
dialog.cancel();
}
});
final AlertDialog dlg = alertDialog.create();
alertDialog.show();
// Showing Alert Message
//alertDialog.setIcon(R.drawable.counter);
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
dlg.dismiss(); // when the task active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
}
}, SPLASH_TIME_OUT); // after 2 second (or 2000 miliseconds), the task will be active.
}
hope to get some good idea.