Added sound to notifications

This commit is contained in:
Keith Holliday 2016-07-11 14:07:33 -05:00
parent ccc937d2cf
commit 364caa4646
2 changed files with 13 additions and 7 deletions

View file

@ -10,7 +10,10 @@ import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
/**
* Created by keithholliday on 5/29/16.
@ -42,15 +45,17 @@ public class TaskReceiver extends BroadcastReceiver {
public void createNotification() {
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, 0);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification notification = new Notification.Builder(context)
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_gryphon)
.setContentTitle(taskTitle)
.setContentText(taskTitle).setSmallIcon(R.drawable.ic_gryphon)
.setContentIntent(pendingIntent)
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
.setContentText(taskTitle)
.setSound(soundUri)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
notificationManager.notify((int) System.currentTimeMillis(), notification);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());
}
}

View file

@ -14,6 +14,7 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.util.Calendar;
import java.util.Date;