Amadeus/app/src/main/java/com/example/yink/amadeus/AlarmService.java

41 lines
1.5 KiB
Java

package com.example.yink.amadeus;
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
public class AlarmService extends IntentService {
public static final int ALARM_NOTIFICATION_ID = 102434;
public AlarmService() {
super("AlarmService");
}
@Override
public void onHandleIntent(Intent intent) {
sendNotification(getString(R.string.incoming_call));
Intent launch = new Intent(this, LaunchActivity.class);
startActivity(launch);
AlarmReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String msg) {
NotificationManager alarmNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, LaunchActivity.class), 0);
NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(
this).setContentTitle(getString(R.string.app_name)).setSmallIcon(R.drawable.incoming_call)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
alarmNotificationBuilder.setContentIntent(contentIntent);
alarmNotificationManager.notify(ALARM_NOTIFICATION_ID, alarmNotificationBuilder.build());
}
}