BroadcastReceiver onReceive open dialog - android

I'm building an android application with BroadcastReceiver and I want to show a dialog when onReceive starts.
I want to show the dialog on the phone (show the user a dialog no matter where he is, like the whatsapp dialog when you get a message).
How I can do that?
Thanks!

If you want to show a dialog from inside your onReceive of the BroadcastReceiver, inside your broadcast receiver you may start a transparent activity with an alert dialog and NEVER called setContentView(). The activity will have an transparent view and only the alert dialog will show.
Source: show an alert dialog in broadcast receiver after a system reboot
There are many similar posts which talk about this topic. See below questions for code samples and other reviews on the same:
AlertDialog from within BroadcastReceiver?? Can it be done?
How to raise an alert dialog from BroadcastReceiver class?
How can I display a dialog from an Android broadcast receiver?
How to setup Alertbox from BroadcastReceiver
Hope this will help.

Related

How to show a dialog notification in Android instead of only appear in notification center?

I did an app that receive push notification, but the notification only show in the notification center.
But I saw that when I received a message from whatsapp, it popup a big dialog even I closed the app.
How does it possible?
Some screenshots:
http://2.bp.blogspot.com/-8WTQisLNIL0/T_O_InFxr6I/AAAAAAAACA4/fdh10K0W79s/s1600/PrtScn20120704114902.jpg
http://www.whatsappen.nl/wp-content/uploads/2012/05/popup21.jpg
https://lh4.ggpht.com/Mopo8Uwh3u7mAOqh7_1LBnquLLVe_TaZfeRfZiBx3QoohOVv9qEm1TUNXUEx5MRKrrs=h900
First create a broadcast receiver class by extending BroadcastReceiver and declare it in manifest with intent filter broadcast action. Create an activity and cal only dialog it its onCreate method.Override the onReceive method of broadcast receiver class and call the activitty there. Declare the activity in manifest with
android:theme="#android:style/Theme.Dialog"
In your notification code braocast the intent with specific braodcast action

Android - jelly bean notification dismiss button

The google play music app has a little 'X' in the top right corner, instead of displaying the time and a miniature notification icon in that location. Tapping the button kills the player and closes the notification. Great!
I'd like to do the same with my app - Is this only possible by inflating remote views and associating a custom button with an intent to destroy the service, or is there some notification builder methods that I'm overlooking which do that job?
There are no notification builder methods which achieve this. The only solution is to create a custom button with a pending intent to perform the action required.

how to pop up alarm even when the application is closed

I'm developing a location based alarm which is an Android application.
All the coding part has been done.
But the alarm alert dialog is not displaying when the application is closed.
Please help me, I'm trying to pop up the alarm even when user is using another application or is in the home screen.
The code of my alarm at the moment is shown below:
final MediaPlayer mp = MediaPlayer.create(LocAlarmProject.this, R.raw.airtel);
mp.start();
// LocAlarmProject.this below is what's causing the problem:
final AlertDialog.Builder builder=new AlertDialog.Builder(LocAlarmProject.this);
builder.setTitle(disp_title);
builder.setMessage(disp_desc);
builder.setIcon(R.drawable.alarm);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mp.stop();
}
});
builder.show();
I am pretty sure you are looking for Service.
Copied and Paste:
A Service is an application component representing either an
application's desire to perform a longer-running operation while not
interacting with the user or to supply functionality for other
applications to use. Each service class must have a corresponding
declaration in its package's AndroidManifest.xml. Services
can be started with Context.startService() and Context.bindService().
Use Notification service to keep track of the status.....visit......http://developer.android.com/guide/topics/ui/notifiers/notifications.html
The proper way to do this requires a few steps. Sorry, it's not trivial if you haven't done it before:
First, you're going to use Android's built-in AlarmManager to schedule the time you want your app to be activated. You schedule a new alarm with the time to wake up and a PendingIntent.
Second, create your PendingIntent that's used to activate your app for the time to show the alarm.
Third, you can handle this Intent several ways, the most common is to create a class that extends BroadcastReceiver to receive the Intent. This class is notified when it's time to show the alarm. The Intent that you created and put inside your PendingIntent is passed to its onReceive() method. You pass this information to your app to display the alert dialog. --- You can alternatively just register your main app to receive the Intent instead, then override the onNewIntent(Intent) method in your Activity.
Four, register your BroadcastReceiver in your AndroidManifest.xml file. This is also the place to register this receiver to listen for the Intent you created. You do this using the <intent-filter> tag.
Five, (optional) if you want your alarm to display even if the phone is asleep, and you want to make sure it doesn't go back to sleep before the user acknowledges the alarm, you'll need to obtain a WAKE_LOCK to do so.
The reason this is preferable to using a Service is it doesn't consume resources just to wait for the alarm, and also it still works if Android decides to kill your app free up memory. Good luck and happy coding!

Android: How can I open a dialog which is started while sleep?

In my app I have a service which has a BroadcastReceiver which listens to TIME_TICK.
I already could check if a date is reached. So if for excemple the 04.01.2011 11:00 pm is reached there is a vibration alarm.
But how could I open a dialog so that after I unlocked my screen it is shown?
Launch an intent for an activity when the time is reached.
Declare on the manifest a theme for this activity like:
android:theme="#android:style/Theme.Dialog"
and create a view for the activity just like the inside of a dialog, so you don't need to create an AlertDialog.

Android Alert manager delete

I have set an alert manager for every event created by user. If any user delete the event after that, I want to delete the alert manager set for the specific event. How to delete any specific alert programmatically?
I have set an alert manager for every event created by user.
I am going to assume that you really mean that you have set an alarm with AlarmManager.
How to delete any specific alert programmatically?
Call cancel() on AlarmManager with a PendingIntent for an equivalent Intent. Here is a sample project that demonstrates this (see OnBootReceiver.java).

Categories

Resources