I work in Android Studio and try to generate a notification about specific dates and times. Everything goes right, but in my service class the setLatestEventInfo () method cannot be resolved. I did the same demo in eclipse and there is no problem with eclipse. I do not want to generate a notification about any button click or generate any event manually, but at certain dates and times, as I indicated.
The code for the service class is as follows:
public class MyRemiderService extends Service {
private NotificationManager mManager;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
@Deprecated
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
mManager = (NotificationManager) getApplicationContext()
.getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(),
HomeActivity.class);
Notification notification = new Notification(R.drawable.notification_template_icon_bg,
"This is a test message!", System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
this.getApplicationContext(), 0, intent1,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this.getApplicationContext(),
"AlarmManagerDemo", "This is a test message!",
pendingNotificationIntent);
mManager.notify(0, notification);
}
@Override
public void onDestroy() {
super.onDestroy();
}
Please let me provide a solution on this .. Thanks.
source
share