lundi 13 avril 2015

Notifications didn't show up at specified time


Vote count:

0




What's wrong with this scrap of code? It should came up with an notification at specified time. I have done some testing and logging, but nothing has changed - notifications has never showed up...


NotificationService.java



import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;

public class NotificationService extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String link = "http://www.login.lt/apdovanojimai/";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(link));
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

NotificationCompat.Builder n = new NotificationCompat.Builder(this)
.setContentTitle("LOGIN 2015")
.setContentText(getResources().getString(R.string.rate_at_login))
.setSmallIcon(R.drawable.logo)
.setContentIntent(pIntent)
.setAutoCancel(true);

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, n.build());
}
}


setAlarm():



private void setAlarm() {
Intent myIntent = new Intent(this , NotificationService.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);

Calendar date1 = Calendar.getInstance();
date1.set(2015, 04, 16, 19, 00, 00);

Calendar date2 = Calendar.getInstance();
date2.set(2015, 04, 24, 19, 00, 00);

alarmManager.set(AlarmManager.RTC_WAKEUP, date1.getTimeInMillis(), pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, date2.getTimeInMillis(), pendingIntent);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24 * 60 * 60 * 1000 , pendingIntent);
}


MainActivity.java:



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
setAlarm();
}


asked 33 secs ago







Notifications didn't show up at specified time

Aucun commentaire:

Enregistrer un commentaire