Created
July 18, 2020 12:28
-
-
Save garnesapps/227b990aee548ca936ca4ff9614c77f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyAlarm extends BroadcastReceiver { | |
private NotificationManager alarmNotificationManager; | |
String NOTIFICATION_CHANNEL_ID = "channel_id"; | |
String NOTIFICATION_CHANNEL_NAME = "nama channel"; | |
@Override | |
public void onReceive(final Context context, Intent intent) { | |
// menjalankan audio | |
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.adzan); | |
mediaPlayer.start(); | |
sendNotification(context, intent); | |
} | |
private void sendNotification(Context context, Intent itn) { | |
String notif_title = itn.getExtras().getString("title"); | |
String notif_message = itn.getExtras().getString("message"); | |
alarmNotificationManager = (NotificationManager) context | |
.getSystemService(Context.NOTIFICATION_SERVICE); | |
Intent newIntent = new Intent(context, LoadActivity.class); | |
newIntent.putExtra("notifkey", "notifvalue"); | |
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, | |
newIntent, PendingIntent.FLAG_UPDATE_CURRENT); | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | |
int importance = NotificationManager.IMPORTANCE_HIGH; | |
NotificationChannel mChannel = new NotificationChannel( | |
NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance); | |
alarmNotificationManager.createNotificationChannel(mChannel); | |
} | |
NotificationCompat.Builder alamNotificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID); | |
alamNotificationBuilder.setContentTitle(notif_title); | |
alamNotificationBuilder.setContentText(notif_message); | |
alamNotificationBuilder.setSmallIcon(R.mipmap.ic_launcher); | |
alamNotificationBuilder.setAutoCancel(true); | |
alamNotificationBuilder.setContentIntent(contentIntent); | |
alarmNotificationManager.notify(itn.getExtras().getInt("id"), alamNotificationBuilder.build()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment