1

我按照本指南发出通知,我正在 SDK-17 (minSdk 13) IntentService 类上使用此代码。

private final int NOTIFICATION_ID=6317;
Notifiaction.Builder builder;
private void startNotification(int backupNumber) {
    builder=new Notification.Builder(this);
    builder.setContentTitle("Backup");
    builder.setContentText(getString(R.string.backup_of)+backupNumber+"app(s)");
    builder.setSmallIcon(android.R.drawable.stat_sys_download);
    Intent notificationIntent = new Intent(this, Launchalot.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    builder.setContentIntent(pendingIntent);
    mNotificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    startForeground(NOTIFICATION_ID, builder.build());
}

我还在其他方法中使用 builder.build() 来更新通知

当我尝试编译它时,蚂蚁找不到 build() 方法:

[javac] /home/edo/Dropbox/android_projects/AppShare/src/it/ptia/appshare/BackupService.java:44: error: cannot find symbol
[javac]                 mNotificationManager.notify(NOTIFICATION_ID, builder.build());
[javac]                                                          ^
[javac]   symbol:   method build()
[javac]   location: variable builder of type Builder
[javac] /home/edo/Dropbox/android_projects/AppShare/src/it/ptia/appshare/BackupService.java:65: error: cannot find symbol
[javac]             mNotificationManager.notify(NOTIFICATION_ID, builder.build());
[javac]                                                      ^
[javac]   symbol:   method build()
[javac]   location: variable builder of type Builder
[javac] /home/edo/Dropbox/android_projects/AppShare/src/it/ptia/appshare/BackupService.java:107: error: cannot find symbol
[javac]         startForeground(, builder.build());
[javac]                                      ^
[javac]   symbol:   method build()
[javac]   location: variable builder of type Builder
[javac] 3 errors
4

1 回答 1

0

build() 调用是 API 16,你的最小值是 13

getNotification当 API 低于 16 时可以使用

于 2013-07-15T10:29:05.110 回答