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?