我创建了以下课程: 的 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());
}