AlertDialog after tapping on Android notification - android

When a notification appears in the Android notification bar, the action for tapping on it is defined by the PendingIntent that was used while creating it, right?
But instead of launching an activity when the user taps on the notification, I would rather like to show an AlertDialog only. Is this possible?
The AlertDialog should ask: "Close notification" or "Show again in 1h" and so on.
Is there a way to show this AlertDialog only or do I have to launch an Activity, anyway?

You have to make an activity that does not set a contentView and just pops the Dialogue.
And remember to finish(); the activity when the dialogue is dimissed.

Related

how to show custom dialog box when android application receives notification

popup message feature like whats app, caller id like the true caller, I am trying to make the same thing.
I tried using a broadcast receiver but I do not know how to show the dialog box when a broadcast receives a notification.
a pop-up message like WhatsApp shows when a notification arrives on a phone.
Set mainactivity as a launcher screen. In the mainactivity before setContentView method calling check if the intent has extra parameters as per your requirement. If yes, then finish the current activity and start DialogActivity.

How to show an alert dialog without activity background

I am creating notification using below code.
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "Don't forget", System.currentTimeMillis());
notification.defaults|=Notification.DEFAULT_SOUND;
notification.defaults|=Notification.DEFAULT_LIGHTS;
notification.defaults|=Notification.DEFAULT_VIBRATE;
Intent intent2 = new Intent(Create_notification.this,After_alarm.class);
intent2.putExtra("arr", arr);
PendingIntent pintent = PendingIntent.getActivity(Create_notification.this, 0,intent2 ,0 );
nm.notify(i, notification);
I want to show some string on alert dialog after clicking on notifiction.For doing this I created Alert dialog in the oncreate() of the activity(i.e After_alarm activity) but this is showing the background of After_alarm activity and an alert dialog on it.I Only want to show alert dialog.Is their is a way to make an activity visible like alert dialog.I also changed theme of After_alarm of activity to alertdialog but dis is not wat I want.It is occupying a large space of screen.
Plz help me
thnx
As I said in the comment, you can make your activity transparent and show Alert Dialog on top of it. See answers How do I create a transparent Activity on Android? and how to make activities transparent for how to make it transparent. Hope it helps.
You could use .setVisibility(View.GONE) which will work fine.
alertdialog.setVisibility(View.GONE);

Android Services, Activities and Handlers?

Im developping an Android Service in Android that needs to pop-up a new dialog box for confirmation.
I can popup a new activity using Intent and Context
Intent myIntent = new Intent(context, ConfirmationActivity.class);
But then I need to handle the option selected in the dialog box (OK or Cancel).
Any suggestion?
Note: Not developing for smartphones.
Update: I need to return the result to the place I call the Dialog.
A service should not pop up anything at all. Imagine the user is in the middle of a phone call when your dialog pops up.
If you need a confirmation from the user the best thing you can do is to use the NotificationManager and use a PendingIntent to launch an Activity. The Activity can still have a dialog style if you like.
Control flows back from the Activity to your Service then, so when the user presses ok or cancel you would either call a bound interface or use SharedPreferences to tell the service about the user's choice.

when user clicks on my notification i want to show an AlertDialog there

how can i show an AlertDialog in my activity, when the notification is clicked in notification area.
plz help....
i'm using multiple status bar notifications each with unique IDS.
I've solved a similar problem by having the notification intent open a new activity with a transparent background. The activity then spawns the AlertDialog.
Put some data to signal that an AlertDialog should be shown into a PendingIntent and put this into yourNotification.contentIntent of your notification. Display the AlertDialog from your Activity in case it receives this Intent.
Have a look at the Notifications Doc.

Android - How to display a dialog over a native screen?

I was wondering if anyone can tell if how to pop a dialog screen up over a native Android screen?
I currently have an application that traps an outgoing call and stops it, I then want to pop up a dialog that would take over from the dialler screen and alert the user that there attempt to call has been blocked and allow them have some new options from the dialog.
I know that some people will say that I should use notifications instead but I'm aware of that and its not the way that it should work, I need to be able to pop up a dialog when the call gets trapped.
This is my dialog code so far
AlertDialog LDialog = new AlertDialog.Builder(context)
.setTitle("Call Blocked")
.setMessage("Call Blocked, reroute call?")
.setPositiveButton("ok", null).create();
LDialog.show();
I presume I have to somehow get the context to be that of the dialler screen?
Can anyone offer any help and assistance or links to tutorials?
Thanks in advance
For my application I used an activity with the Dialog theme.
You can declare the theme in the manifest file :
<activity android:name="PopupActivity"
android:launchMode="singleInstance" android:excludeFromRecents="true"
android:taskAffinity="" android:theme="#android:style/Theme.Dialog" />
use launcheMode="singleInstance" and taskAffinity="" if your popup is detached from your main application. Otherwise user may click the back button and return to the previous activity of your application.
excludeFromRecents="true" to avoid your popup to appear in recent tasks (long press home)
theme="#android:style/Theme.Dialog" to set the Dialog theme.
How to get the equivalent of launchMode = singleTask in code
I have not seen a clear explanation of how to set these flags programmatically, so I will include my results here. tldr: you have to set FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_MULTIPLE_TASK.
If you launch this directly from your app, your dialog will appear on top of your app's last Activity. But if you use a PendingIntent broadcast by AlarmManager to launch your "dialog", you have time to switch to a different app so you can see that your "dialog" will appear over that other app, if the style is set appropriately to show what is behind it.
Obviously one should be responsible about when it is appropriate to display a dialog on top of other apps.
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// you have to set these flags here where you receive the broadcast
// NOT in the code where you created your pendingIntent
Intent scheduledIntent = new Intent(context, AlertAlarmActivity.class);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(scheduledIntent);

Categories

Resources