Last active
October 18, 2018 12:49
-
-
Save choiks14/24106a74c5f39ce6c25d778537a2d157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void showNotification(String title, String message, Intent intent) { | |
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), Defines.REQUEST_GOTO_HOME, intent, PendingIntent.FLAG_ONE_SHOT); | |
Notification.Builder builder = new Notification.Builder(this); | |
builder.setSmallIcon(R.mipmap.ic_launcher); | |
builder.setShowWhen(true); | |
builder.setContentTitle(title); | |
builder.setContentText(message); | |
builder.setTicker(message); | |
builder.setWhen(System.currentTimeMillis()); | |
builder.setContentIntent(pendingIntent); | |
builder.setPriority(Notification.PRIORITY_MAX); | |
builder.setDefaults(Notification.DEFAULT_ALL); | |
builder.setAutoCancel(true); | |
if (android.os.Build.VERSION.SDK_INT >= 21) { | |
builder.setColor(getApplication().getResources().getColor(R.color.colorAccent)) | |
.setVisibility(Notification.VISIBILITY_PUBLIC); | |
} | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
NotificationChannel notificationChannel = new NotificationChannel(MyApplication.CHANNEL_ID, MyApplication.CHANNEL_ID, NotificationManager.IMPORTANCE_MAX); | |
notificationChannel.setDescription("channel description"); | |
notificationChannel.enableLights(true); | |
notificationChannel.enableVibration(true); | |
notificationChannel.setVibrationPattern(new long[]{100, 200, 100, 200}); | |
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); | |
notificationManager.createNotificationChannel(notificationChannel); | |
builder.setChannelId(notificationChannel.getId()); | |
} | |
Notification notification = builder.build(); | |
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
nm.notify(Defines.NOTI_PUSH, notification); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment