API级别低于26的通知代码

时间:2019-06-06 15:18:36

标签: java android notifications

我正在尝试将我的Android应用程序从API级别23定位到最新的API级别。但是,从Android 8.0(API级别26)开始,必须将所有通知分配给以前不是这种情况的频道。现在,如果API级别大于26,我正在检查条件Sub ColorCompanyDuplicates() Worksheets("Master Filtered").Activate Dim xRg As Range Dim xTxt As String Dim xCell As Range Dim xChar As String Dim xCellPre As Range Dim xCIndex As Long Dim xCol As Collection Dim I As Long Dim lastrow As Long lastrow = Cells(Rows.Count, 1).End(xlUp).Row On Error Resume Next If ActiveWindow.RangeSelection.Count > 1 Then xTxt = ActiveWindow.RangeSelection.AddressLocal Else xTxt = ActiveSheet.UsedRange.AddressLocal End If Set xRg = ThisWorkbook.Worksheets("Master Filtered").Range("C4:C" & lastrow) If xRg Is Nothing Then Exit Sub xCIndex = 2 Set xCol = New Collection For Each xCell In xRg On Error Resume Next xCol.Add xCell, xCell.Text If Err.Number = 457 Then xCIndex = xCIndex + 1 Set xCellPre = xCol(xCell.Text) If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex xCell.Interior.ColorIndex = xCellPre.Interior.ColorIndex ElseIf Err.Number = 9 Then MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel" Exit Sub End If On Error GoTo 0 Next End Sub 以便通过NotificationChannel进行通知,所以我的问题是NotificationChannel if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)的import语句  会导致API版本低于26的问题。我应该为不同的API维护不同的活动吗?

1 个答案:

答案 0 :(得分:0)

  

NotificationChannel的import语句将导入android.app.NotificationChannel;导致API版本低于26的问题。

否。

尝试在较旧的设备上使用 NotificationChannel是一个问题,但这就是if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)的目的。只需导入就不会有问题。