2017-01-06 46 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

貴問題得到解決 –