Enrich your program, use mobile multimedia

Source: Internet
Author: User

Enrich your program and use mobile multimedia notifications
    • Notifications (Notification) are a feature of the Android system that can be implemented with notifications when an application wants to send some to the user, and the application is not running in the foreground.
Basic usage of notifications
  • First, a notificationmanager is required to manage the notification, which can be obtained by invoking the Getsystemservice () method of the context. Getsystemservice () receives a parameter of Context.notification_service.

    NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  • Create a Notification object This object is used to store the various information required by the notification

    • The first parameter specifies an icon for the notification
    • The second parameter is used to specify the ticker content of a notification
    • The third parameter specifies the time, in milliseconds, that a notification is created

      Notification notification = new Notification(R.drawable.icon,"This is ticker text"</span>,System.currentTimeMillis());
  • Call Notification's Setlatesteventinfo () method to set a standard layout for the notification

    • The first parameter is a Context
    • The second parameter is used to specify the title of the notification, and the drop-down system status bar will see this part
    • The third parameter is used to specify the body content of a notification
    • The fourth parameter is Pendingintent
      notification. Setlateseventinfo (Context, "This is thecontent title", "This iscontent text", pendingintent);
  • Call Notificationmanager's Notify () method to make the notification appear

    Manager. Notify (1, notification);
  • Notificationmanager Cancel () method cancels the notification


  • # # # Pendingintent
  • Intent is more inclined to perform an action immediately, while Pendingintent is more inclined to perform an action at a suitable time.
  • Pendingintent a simple understanding of deferred execution of the intent.
  • Methods for getting pendingintent: Getactivity (), Getbroadcast (), GetService ().
    • The first parameter is still a Context
    • The second parameter is generally not used, and is usually passed in 0.
    • The third parameter is a Intent object, which allows us to construct a pendingintent "intent".
    • The fourth parameter is used to determine the behavior of the pendingintent, with the four values of Flag_one_shot, Flag_no_create, Flag_cancel_current, and flag_update_current optional,
Advanced Tips for Notifications
  • The sound property can play a piece of audio in the notification

    Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/Basic_tone.ogg"));notification.sound = soundUri;
  • Vibrate property allows the phone to vibrate

    Long[] vibrate = {0,1000,1000,1000};
    Notification.vibrate = vibrates;

  • Control the phone's LED light display

    • Edargb for controlling the color of LED lights
    • Ledonms used to specify the length of time, in milliseconds, that LED lights are lit
    • The LEDOFFMS is used to specify the length of time the LED light goes dark, and also in milliseconds
    • Flags can be used to specify some of the behavior of the notification, including the option to display the LED light
    notification.ledARGB = Color.GREEN;notification.ledOnMS1000;notification.ledOffMS1000;notification.flags = Notification.FLAG_SHOW_LIGHTS;
Play multimedia files Play audio

Play Video

Enrich your program, use mobile multimedia

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.