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());
Jack Fan
Email: juan850311@163.com
QQ: 441935503
Email: juan850311@163.com
QQ: 441935503