如何将文本设置到android Ex:hello world
中的顶部通知栏答案 0 :(得分:0)
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);
我使用此代码在通知栏上显示通知,您可以根据您的要求进行更改。 我希望这是有帮助的。