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

Jay*_*eja 2 notifications android

我想通过发生特定事件通知移动用户,使用通知栏图标.有没有办法做同样的事情?

pra*_*tik 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);
Run Code Online (Sandbox Code Playgroud)

}