如何在特定活动中通知用户?

时间:2012-03-28 09:27:36

标签: android notifications

我希望在发生特定事件时通知移动用户,使用通知栏图标。 有没有办法做同样的事情?

3 个答案:

答案 0 :(得分:5)

在您需要的地方使用此方法。正确地为我工作。 希望它能解决你的问题。

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);

}

答案 1 :(得分:1)

使用Android NotificationManager(http://developer.android.com/reference/android/app/Notification.html) 请参阅应用开发指南示例 - http://developer.android.com/guide/topics/ui/notifiers/notifications.html

设置所需属性并调用notify方法后,状态栏将显示您需要的通知。

Omkar Ghaisas

答案 2 :(得分:1)

您可以随时前往pop ups。它们很整洁,让您有机会通知用户。另外,您也可以使用toast。只是吐司的问题是它会出现一段时间然后消失,所以如果用户错过了吐司,他可能永远不会知道吐司。或者说通知。您可以看到示例here

相关问题