Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends AppCompatActivity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.notification);
- Button btn = findViewById(R.id.button);
- btn.setOnClickListener(v -> {
- NotificationManager manager = getSystemService(NotificationManager.class);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- //create the NotificationChannelGroup first as the NotificationChannel requires one
- NotificationChannelGroup channelGroup = new NotificationChannelGroup("Notifica", "Notifica");
- String groupDescription = "group description";
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
- channelGroup.setDescription(groupDescription);
- }
- manager.createNotificationChannelGroup(channelGroup);
- NotificationChannel channel = new NotificationChannel("Notifica", "Notifica", NotificationManager.IMPORTANCE_HIGH);
- channel.setGroup(channelGroup.getId()); //This was "n" but should be "Notifica" (the ID of the group we created)
- manager.createNotificationChannel(channel);
- System.out.println(manager.getNotificationChannel("Notifica"));
- }
- NotificationCompat.Builder notifica = new NotificationCompat.Builder(Main.this, "Notifica")
- .setPriority(4)
- .setSmallIcon(R.drawable.ic_launcher_background)
- .setContentTitle("Circolare")
- .setContentText("Nome Circolare")
- .setGroup("n")
- .setChannelId("Notifica");
- System.out.println(notifica);
- manager.notify(1, notifica.build());
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement