Android developed a method for displaying reminder messages using the notification bar

  • 2021-01-03 21:02:13
  • OfStack

This article illustrates how Android uses the notification bar to display notifications. To share for your reference, the details are as follows:

Use the notification bar


public void notifyKJ() {
 // Get the notification manager. Notifications are 1 Item system Service 
 NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
 // Initializes the notification object  p1: Notification icon  p2: The status bar of the notification displays a prompt  p3: The time the notification is displayed 
 Notification notification = new Notification(R.drawable.kjalarm, " remind ", System.currentTimeMillis());
 // Click on the notification Intent , this example is still in the current interface after clicking 
 Intent descIntent = new Intent(context, com.acp.main.DesktopUI.class);
 descIntent.putExtra(DesktopUI.requestCode,DesktopUI.KJ);
 PendingIntent intent = PendingIntent.getActivity(context, 0, descIntent, 0);
 // Set notification information 
 notification.setLatestEventInfo(context, " remind ", " I wish you happiness every day ", intent);
 notification.flags|=Notification.FLAG_AUTO_CANCEL; // When viewed, it automatically disappears 
 notification.defaults |= Notification.DEFAULT_SOUND;// Default sound prompt 
 // notice 
 manager.notify(NOTICE_ID, notification);
}

Automatically jump to the network Settings interface

context.startActivityForResult(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS),0);

I hope this article has been helpful in Android programming.


Related articles: