setLatestEventInfo cannot be resolved

后端 未结 1 1035
天命终不由人
天命终不由人 2021-01-18 18:39

I am trying to do a notification on api level 10 and below is my code but im getting a syntax error setLatestEventInfo cannot be resolved. I am guessing its something to do

1条回答
  •  悲&欢浪女
    2021-01-18 19:06

    If your compile SDK version is set to api 23+ you'll see this issue. This method was removed in M (api 23).

    To do notifications for api 4 onwards you can use the NotificationCompat.Builder which was added in the Android Support Library. The Android Documentation has a decent example:

     Notification noti = new Notification.Builder(mContext)
             .setContentTitle("New mail from " + sender.toString())
             .setContentText(subject)
             .setSmallIcon(R.drawable.new_mail)
             .setLargeIcon(aBitmap)
             .build();
    

    You can replace "Notification.Builder" for "NotificationCompat" if need to support older api versions.

    0 讨论(0)
提交回复
热议问题