Notification用法

String message = "You should click come back now. It is time out more than 10 minutes.";
// MessageDialog.showMessageDialog(MainActivity.act, message); Intent intent = new Intent(MainActivity.this, MainActivity.class);
// intent.setAction(Intent.ACTION_MAIN);
// intent.addCategory(Intent.CATEGORY_LAUNCHER);
// intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0 /* Request code */, intent,
PendingIntent.FLAG_CANCEL_CURRENT); //PendingIntent.FLAG_UPDATE_CURRENT // Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this)
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(R.drawable.ba)
.setContentTitle(getString(R.string.app_name))
.setContentText(message)
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_MAX)
// .setSound(defaultSoundUri)
.setContentIntent(pendingIntent); NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); long time = new Date().getTime();
String tmpStr = String.valueOf(time);
String last4Str = tmpStr.substring(tmpStr.length() - 5);
int mId = Integer.valueOf(last4Str);
notificationManager.notify(mId /* ID of notification */, notificationBuilder.build());

  

上一篇:linux终端下一些“风骚”的按键操作及Linux终端命令


下一篇:android之AlertDialog 点击其它区域自己主动消失