-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyBroadcastReceiver.java
41 lines (29 loc) · 1.27 KB
/
MyBroadcastReceiver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.example.alarmpart;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
@TargetApi(16)
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Vibrator vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
Notification notif = new Notification.Builder(context)
.setContentTitle("Alarm is ON")
.setContentText("You set the ALARM")
.setSmallIcon(R.mipmap.ic_launcher).build();
NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notif.flags|= Notification.FLAG_AUTO_CANCEL;
manager.notify(0,notif);
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Ringtone r = RingtoneManager.getRingtone(context,notification);
r.play();
}
}