Guest User

Untitled

a guest
Dec 7th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. @Override
  2. public void onCreate() {
  3. super.onCreate();
  4. if (Build.VERSION.SDK_INT >= 26) {
  5. String CHANNEL_ID = "my_channel_01";
  6. NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
  7. "My Channel",
  8. NotificationManager.IMPORTANCE_DEFAULT);
  9.  
  10. ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
  11.  
  12. Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
  13. .setContentTitle("A service is running in the background")
  14. .setContentText("").build();
  15.  
  16. startForeground(1, notification);
  17. }
  18. }
Add Comment
Please, Sign In to add comment