Создание будильника из приемника тревог

Я создал следующий класс:AlarmReceiver.java

public class AlarmReceiver extends BroadcastReceiver {

NotificationManager mNotificationManager;

@Override
public void onReceive(Context context, Intent intent) {
    if(Schedule.alarmSetOn){
        Toast.makeText(context, "ALARM START SUCCESSFUL", Toast.LENGTH_SHORT).show();
        /** Show Alarm */

    }
    if(Schedule.notificationSetOn){
        Toast.makeText(context, "NOTIFICATION START SUCCESSFUL", Toast.LENGTH_SHORT).show();
        displayNotification(context);
    }

}

Мне нужно показать будильник с рингтоном по умолчанию на /* Show Alarm */Еще одна проблема, мои текущие уведомления просто добавляются в панель уведомлений без звука и не отображаются в строке состояния. Как бы я это сделал?

  protected void displayNotification(Context context) {
        Log.i("Start", "notification");

   /* Invoking the default notification service */
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);

        mBuilder.setContentTitle("Fitterfox Daily Workout");
        mBuilder.setContentText("Excuses don't burn calories, so get up and start your workout!");
        mBuilder.setTicker("Workout Alert!");
        mBuilder.setSmallIcon(R.drawable.fitterfox_logo);

   /* Increase notification number every time a new notification arrives */


   /* Add Big View Specific Configuration */
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        mBuilder.setStyle(inboxStyle);

   /* Creates an explicit intent for an Activity in your app */
        Intent resultIntent = new Intent(context, MainActivity.class);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MainActivity.class);

   /* Adds the Intent that starts the Activity to the top of the stack */
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(resultPendingIntent);
        mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

   /* notificationID allows you to update the notification later on. */
        mNotificationManager.notify(9999, mBuilder.build());
    }

0 ответов

Другие вопросы по тегам