android - 如何在特定事件中通知用户?

标签 android notifications

我想在特定事件发生时通知移动用户,使用通知栏图标。 有什么方法可以做到这一点吗?

最佳答案

在您需要的地方使用此方法。它对我很有效。 希望它能解决您的问题。

private void notification(Context c) 
{
 // TODO Auto-generated method stub
    EfficientAdapter1 e1=new EfficientAdapter1(c);
    String ns = Context.NOTIFICATION_SERVICE;

    NotificationManager mNotificationManager = (NotificationManager) e1.no(ns);

    //int icon = R.drawable.xyz;//your image
    CharSequence tickerText = "ticker text";
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, Text, when);

    Context context = c;
    CharSequence contentTitle = "your title";
    CharSequence contentText = " your text";
    Intent notificationIntent = new Intent(context, ViewAllSMS.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    final int HELLO_ID = 1;

    notification.flags = Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL;

    mNotificationManager.notify(HELLO_ID, notification);

关于android - 如何在特定事件中通知用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9904650/

相关文章:

android 版本控制 Mercurial 与保管箱(如果可能)

cocoa - 当鼠标悬停在特定 NSMenuItem 上时收到通知

xcode - UNUserNotificationCenter 确实收到了完成处理程序的响应,从未被称为 iOS10,swift 2.3

android - 如何在应用程序启动器图标中显示通知数量

android - cordova/phonegap 推送通知 unregister() 即使在关闭互联网的情况下也会返回成功

android - tablerow 中的复选框被 textview 推离屏幕

java - 错误 : java.net.UnknownHostException : Unable to resolve host "api. themoviedb.org

java - String Arraylist 获取以该字符串开头的项

android - Android 中 FrameLayout 内的最大 subview 数是多少?

amazon-web-services - s3api put-bucket-notification-configuration 删除现有事件