How to implement the deprecated methods of Notification

后端 未结 2 1395
甜味超标
甜味超标 2020-11-30 03:34

I have a small problem but dont understand how to get out of this.

I created a class for providing Notifications, but these lines are marked deprecated:



        
2条回答
  •  一生所求
    2020-11-30 03:46

    This is the correct way to get the level.

     final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
    
    if (sdkVersion < Build.VERSION_CODES.HONEYCOMB)
    {
    ...
    Notification notification = new Notification(icon, text, time); // deprecated in API level 11
    ...
    notification.setLatestEventInfo(this, title, text, contentIntent); // deprecated in API level 11
    ...
    }
    else
    {
    Notification noti = new Notification.Builder(mContext)
             .setContentTitle("New mail from " + sender.toString())
             .setContentText(subject)
             .setSmallIcon(R.drawable.new_mail)
             .setLargeIcon(aBitmap)
             .build(); // available from API level 11 and onwards
    } 
    

    All the version codes can be found at this developer link.

提交回复
热议问题