我希望在发生特定事件时通知移动用户,使用通知栏图标。 有没有办法做同样的事情?
答案 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)