我无法弄清楚为什么会发生此错误。我正在创建一个警报按钮,向用户发送VIA振动通知。
" new NotificationCompat()"是我的错误。
这是代码:
public class AlertReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
createNotification(context, "It Is Time To Stand Up!","20 Minutes Have Passed", "Alert");
}
public void createNotification(Context context, String msg, String msgText, String msgAlert ) {
PendingIntent notificIntent = PendingIntent.getActivity(context,0,new Intent(context,CustomizeAlertsPage.class),0);
NotificationCompat.Builder mBuilder = new NotificationCompat().Builder(context)
.setLargeIcon(R.drawable.ALERT)
.setContentTitle(msg)
.setTicker(msgAlert)
.setContentText(msgText);
mBuilder.setContentIntent(notificIntent);
mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1,mBuilder.build());
}
}

答案 0 :(得分:4)
更改
NotificationCompat.Builder mBuilder = new NotificationCompat().Builder(context)
到
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
答案 1 :(得分:0)
new NotificationCompat().Builder()
将首先创建NotificationCompat
类实例,然后尝试在其中找到名为Builder
的内容。
您需要像这样重写此行:
new NotificationCompat.Builder()
以便new
创建在Builder
内声明的NotificationCompat
类实例。