【发布时间】:2014-01-10 09:20:38
【问题描述】:
此代码适用于 2.3 以上版本(不适用于 2.3)
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.abc_logo)
.setContentTitle("My Title")
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setContentText("My text");
mBuilder.setContentIntent(pendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(NOTIFY_ID, mBuilder.build());
【问题讨论】:
标签: android android-intent notifications android-notifications android-2.3-gingerbread