Уведомление 2019

← разместить еще код

Расшаренный код:

NotificationManager nM = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

final int n_Id = 12; 
String id = "c_Id"; 
 
Intent intent = new Intent(this, MainActivity.class);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

android.support.v4.app.NotificationCompat.Builder builder; 
 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
 
NotificationChannel nC = new NotificationChannel(id, sTitle, NotificationManager.IMPORTANCE_HIGH); 
nC.setDescription(sText);
nC.enableLights(true);
nC.setLightColor(Color.RED); 
nC.setVibrationPattern(new long[0]); 
nC.enableVibration(false); 
nM.createNotificationChannel(nC); 
 
builder = new android.support.v4.app.NotificationCompat.Builder(this, id); 
 
} else { 
 
builder = new android.support.v4.app.NotificationCompat.Builder(this);

} 
 
builder.setContentTitle(sTitle) 
.setContentText(sText)
.setTicker(sText)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setPriority(10)
.setOngoing(false)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent) 
.setVibrate(new long[0]); 

nM.notify(n_Id, builder.build());