Android O notification channel adapter

 After Android O, Google introduced the concept of notification channels, if the target is greater than the API Android O, not directly specify the notification channel is unable to send the notification.

Here I put a written notification method, we can appropriate change to change and then, of course, also be used directly * *

 
    / ** 
     * Send the notification by the notification API new Android O channels 
     * Other still the same as before 
     * 
     * @param channelID channel ID 
     * @param channelName channel name 
     * @param SubText subtitle 
     * @param title title 
     * @param text SUMMARY
      * / 
    @TargetApi (Build.VERSION_CODES.O) 
    public  void the sendNotification (channelID String, String channelName, SubText String, String title, String text) { 

        // create a channel manager 
        NotificationChannel channel = new new NotificationChannel (channelID, channelName, the NotificationManager. IMPORTANCE_HIGH);

        Manager the NotificationManager; 
        Manager = (the NotificationManager) the this .getSystemService (getApplicationContext () NOTIFICATION_SERVICE.); 
        Manager.createNotificationChannel (Channel); 

        // build notices 
        Notification.Builder Builder = new new Notification.Builder (getApplicationContext ());
         // Set small icon 
        builder.setSmallIcon (R.mipmap.ic_launcher);
         // set the notification title, contents, subtitle 
        builder.setContentTitle (title); 
        builder.setContentText (text); 
        builder.setSubText (SubText); 
        // set the color notification 
        builder.setColor (Color.parseColor ( "# E91E63"));
         // set creation time 
        builder.setWhen (System.currentTimeMillis ());
         // specified when creating channelID notice 
        builder.setChannelId (channelID); 

        the Intent resultIntent = new new the Intent ( the this , ClipActivity. Class ); 
        PendingIntent resultPendingIntent = PendingIntent .getActivity ( the this , 0 , resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
        builder.setContentIntent (resultPendingIntent); 

        // build a notification, the notification manager finally transmits 
        the notification notification = builder.build (); 
        manager.notify ( . 1, notification);
    }

 

Guess you like

Origin www.cnblogs.com/dabai2017/p/10979941.html