2
如何設置文本中的Android防爆頂部通知欄:你好世界如何設置狀態欄通知文本的Android
如何設置文本中的Android防爆頂部通知欄:你好世界如何設置狀態欄通知文本的Android
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Notification Receive";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context1 = context;
//*****************
final int CUSTOM_VIEW_ID = 1;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.text, "Racquetime \n"+msg);
notification.contentView = contentView;
notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent;
if(GUIStatics.boolLoginStatus)
{
notificationIntent = new Intent(this,ShowAllNotificationActiviry.class);
}
else{
notificationIntent = new Intent(this, HomeActivity.class);
}
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notificationIntent.putExtra("Tag", "C2DMBaseReceiver");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
mNotificationManager.notify(CUSTOM_VIEW_ID, notification);
我使用這個代碼用於顯示通知欄,您可以更改通知它根據您的要求。 我希望這是幫助。
重複的http://stackoverflow.com/questions/5840166/how-to-set-text-on-status-bar-notification-in-android? – 2011-06-08 12:54:21