Skip to content

Instantly share code, notes, and snippets.

@maoruibin
Created February 25, 2016 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maoruibin/1e14da7a29abd2a7bf9d to your computer and use it in GitHub Desktop.
Save maoruibin/1e14da7a29abd2a7bf9d to your computer and use it in GitHub Desktop.
生成一个处于前台状态的通知
private void showNormalNotification(Context context) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle("Title");
builder.setContentText("Description");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setPriority(NotificationCompat.PRIORITY_MIN);
builder.setOngoing(true);
long[] vibrate = {0, 50, 0, 0};
builder.setVibrate(vibrate);
Notification notification = builder.build();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int NOTIFY_ID = 524947901;
mNotificationManager.notify(NOTIFY_ID, notification);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment