Android NOtification Use (Vibrating splash screen ringtone)

Source: Internet
Author: User

I. Introduction of Notification
In an Android system, the application may encounter several situations that need to be notified to the user, some require a user response, and some do not, for example:
* When events such as save files are completed, a small message should appear to confirm the success of the Save.
* If the application is running in the background and requires the user's attention, the application should create a notification that allows the user to provide convenience in his or her response
* If the application is performing work, the user must wait (for example, to mount the file), the application should show progress or wait for reminders.

For these situations, Android offers a different way of alerting. The following are the main categories:

1.Toast Notification is a temporary notice appearing on the screen that communicates messages of a certain type, and disappears after a short stay without user interaction. such as to inform the download has been completed and so on. (Toast Noification This claim was originally derived from a former MSN employee, because the MSN message reminds of a flick upward from the bottom, the form is like a loaf of bread from the toaster, so called Toast Noification. )
2.Status Bar Notification is a notification that appears in the status bar at the top of the system as an icon or scroll bar text. This is more appropriate when the application is in the background running state. The benefit of this form of notification is that it can be viewed and selectively processed from the top, even if it is noticed without interrupting the current task.
3.Dialog Notification is similar to IOS alert Notification, which appears on the screen as a dialog window for notifications that are important or need to be processed in a timely manner.

Let's look at the entire architecture of the following Android notification. The first two reminders are made by Notificationmanagerservice, and Dialog Notification, which is implemented as a popup window, because most of the reminders are for the current application or process, So it's just a simple and intuitive way of expressing.



Second, the use of notification
1.Toast
Toast is a mechanism used to display information in Android, unlike Dialog, where toast is not focused, and toast is displayed with limited time, and will automatically disappear after a certain amount of time

Use the TOAST method to display the result content
Toast Texttoast=toast.maketext (this, "hint content", toast.length_long);
//... You can also add some properties to the Toast here
Texttoast.show ();
2. StatusBar Notification
StatusBar Notification adds a status bar icon to the system status bar and displays a message in the Notifications window. When the user chooses to expand the message, Android sends a notification (usually the launch of an activity) that defines the intent. You can also configure notifications, reminders and sounds, vibrate the user, and flash lights on the device.
Such notifications are ideal for working with your application in the background service and need to notify the user about the event. If you need to remind you that an event has occurred and that your activity can still be in the current focus, consider using a dialog box notification instead.

StatusBar Notification Basic steps are as follows:

1) Get Notificationmanager:
String ns = Context.notification_service;
Notificationmanager Mnotificationmanager = (notificationmanager) getsystemservice (NS);

2) Create a new Notification object:
Notification Notification = new Notification ();
Notification.icon = R.drawable.notification_icon;
You can also create Notification in a slightly more complex way:
int icon = R.drawable.notification_icon; Notification icon
Charsequence tickertext = "Hello"; Notification text prompt for status bar display
Long when = System.currenttimemillis (); The time the notice is generated will be displayed in the notification message.
Notification Notification = new Notification (icon, Tickertext, when);

3) populate the various properties of the Notification:
Context context = Getapplicationcontext ();
Charsequence contenttitle = "My notification";
Charsequence contenttext = "Hello world!";
Intent notificationintent = new Intent (this, myclass.class);
Pendingintent contentintent = pendingintent.getactivity (this, 0,notificationintent, 0);
Notification.setlatesteventinfo (context, Contenttitle, ContentText, contentintent);

Notification offers a wide range of tips for mobile phones:
A) A notification text prompt that appears in the status bar, such as:
Notification.tickertext = "Hello";

b) Beep tones, such as:
Notification.defaults |= Notification.default_sound;
Notification.sound = Uri.parse ("file:/Sdcard/notification/ringer.mp3");
Notification.sound = Uri.withappendedpath (Audio.Media.INTERNAL_CONTENT_URI, "6");

c) mobile phone vibration, such as:
Notification.defaults |= notification.default_vibrate;
Long[] vibrate = {0,100,200,300};
Notification.vibrate = vibrate;

d) flashing LED lights, such as:
Notification.defaults |= notification.default_lights;
Notification.ledargb = 0xff00ff00;
NOTIFICATION.LEDONMS = 300;
NOTIFICATION.LEDOFFMS = 1000;
Notification.flags |= notification.flag_show_lights;

e) Add remote view
To set the properties of a View in notification by remoteviews
Notification.contentview = new Remoteviews (Getapplication (). Getpackagename (), r.layout.custom_dialog);
Notification.contentView.setProgressBar (R.ID.PB, 0, false);
Notification.contentView.setTextViewText (R.id.tv, "progress" + _progress+ "%");

4) Send notification:
private static final int id_notification = 1;
Mnotificationmanager.notify (Id_notification, NOTIFICATION);


3.Dialog Notification

3.1 Alertdialog

In order to create a warning dialog box, use the Alertdialog.builder subclass. by Alertdialog.builder
Gets a constructor and then uses the public method of this class to define all the properties of the warning dialog box. When you get the constructor, pass create (). method to get the warning dialog object. Sometimes I do not call create (), but instead call Show () to show alertdialog directly after setting it up.

Alertdialog.builder Builder=newalertdialog.builder (this);
Builder.setmessage ("Areyousureyouwanttoexit?");
Alertdialog alert=builder.create ();

3.2 Processdialog

ProgressDialog is an extension of the Alertdialog class that displays a progress animation of a rotating wheel shape for a task that does not define progress, or a progress bar for a task that specifies progress.

ProgressDialog Progressdialog=newprogressdialog (Getapplicationcontext ());
Progressdialog.setprogressstyle (progressdialog.style_horizontal);
Progressdialog.seticon (R.drawable.alert_dialog_icon);
Progressdialog.setmessage ("Loading ...");
Progressdialog.setcancelable (FALSE);

Copy to Google TranslateTranslation Results

Android NOtification Use (Vibrating splash screen ringtone)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.