我想为我的应用实施每日通知。我遇到了AlarmReceiver的问题:
public class AlarmReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, ActivitySplashScreen.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.diamond)
.setContentTitle("Alarm Fired")
.setContentText("Events To be PErformed").setSound(alarmSound)
.setAutoCancel(true).setWhen(when)
.setContentIntent(pendingIntent)
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
notificationManager.notify(MID, mNotifyBuilder.build());
MID++;
}
}
我收到了:Cannot resolve symbol "MID"
请帮帮我们!我第一次遇到这个错误
答案 0 :(得分:0)
MID猜测是一个独特的整数。
您可以尝试(int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE)
这将为每个通知生成唯一的ID
notificationManager.notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), mNotifyBuilder.build());