如何在android中显示简单的通知?

如何在Android的通知栏中显示简单通知? 请帮助我解决最简单的问题。

我假设您在通知栏中询问通知。如果是这样,请尝试此代码,

private void showNotification(String eventtext, Context ctx) { // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.noti_icon, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this // notification PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, MainActivity.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(ctx, "Title", eventtext, contentIntent); // Send the notification. mNM.notify("Title", 0, notification); } 

这很简单。 在此示例中,单击按钮时会触发通知:

    

您也可以在通知中添加声音或振动。 有关更多信息,请参阅本教程。