Android notification syntax, android

Source: Internet
Author: User

Android notification syntax, android

Write as follows:

Public void onCreate () {super. onCreate (); ntfmngr = (icationicationmanager) getSystemService (icationication_service); setNotifyType (R. drawable. logo, "aaaaaaaaaaa", 3);} private void setpolicytype (int icon, String text, int num) {Intent policyintent = new Intent (). setClass (getApplicationContext (), MainActivity. class); // policyintent. putExtra ("mode", mpolicymode); policyintent. setAction (Constants. UPDATE_HOME_LI ST); // determine the type of message based on the received activity that can accept this action. // notifyIntent. setFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP | // Intent. FLAG_ACTIVITY_NEW_TASK); PendingIntent appIntent = PendingIntent. getActivity (this, 0, policyintent, 0); Notification myNotification = new Notification (); // myNotification. defaults = Notification. DEFAULT_VIBRATE; Uri soundUri = Uri. parse ("android. resource: // com. sina. weibo/raw/icationicationsoun D "); // Log. e (Constants. TAG, soundUri. getPath (); myNotification. flags = Notification. FLAG_AUTO_CANCEL; myNotification. icon = icon; <strong> myNotification. defaults = Notification. DEFAULT_SOUND; myNotification. sound = soundUri; // There is a sound when notication comes over </strong> if (num! =-1) {myNotification. number = num;} long [] vb = new long [] {80, 80}; myNotification. vibrate = vb; myNotification. tickerText = text; myNotification. setLatestEventInfo (this, getString (R. string. app_name), text, appIntent); System. out. println ("=== ntfmngr. policy "); <strong> ntfmngr. Y (policy_message, myNotification); </strong> <pre name = "code" class = "java"> <strong> // policy_message is the notification key, can be canceled based on the key </strong>
}

 

You must add the corresponding permissions to obtain the vibration.

<Uses-permission android: name = "android. permission. VIBRATE"/>

You can cancel the notication as follows:

if (ntfmngr != null) {ntfmngr.cancelAll();}



How to Set Notification time in Android Development

Record the Notification content and other information when the time is set. When the time is reached, send the Notification
PendingIntent notiPend = PendingIntent. getActivity (context, 0, intent, PendingIntent. FLAG_CANCEL_CURRENT );
Notification = new Notification (android. R. drawable. stat_policy_sync, policyscroll, System. currentTimeMillis ());
Notification. setLatestEventInfo (context, policytitle, policycontent, notiPend );
Required imgr. Policy (policyid, notification );

Android development: notification compatibility problems

Xiaomi's phone is okay. I just ran this code. What error did you report?

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.