2017-01-06 47 views
0

我想为我的应用程序实施每日通知。我有一个问题AlarmReceiver:通知系统android - 无法解析'MID'

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

MID mus是一个独特的Integer,我猜。 您可以尝试(int) ((new Date().getTime()/1000L) % Integer.MAX_VALUE)

thiswill产生一个唯一的ID为每个通知

notificationManager.notify((int) ((new Date().getTime()/1000L) % Integer.MAX_VALUE), mNotifyBuilder.build()); 
+0

贵问题得到解决 –