【问题标题】:how to play an alarm notification for 10 minutes如何播放 10 分钟的警报通知
【发布时间】:2013-03-16 02:46:45
【问题描述】:

如何在 Android 中播放特定时间段的警报通知(例如连续 10 分钟)?

public class AlarmReciver extends BroadcastReceiver{

 private static int NOTIFICATION_ID = 1;
 Bundle bundle;
 int notificationId = 0;
 AudioManager audioManager;
 @Override
 public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
  try{
     audioManager = (AudioManager) context.getSystemService (Context.AUDIO_SERVICE);
     audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
     int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
     audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0);
      //audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
     notificationId = intent.getExtras().getInt("notificationId");
     NotificationManager manger = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "YourBestSelfApp", System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults =  Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS;
notification.sound = Uri.parse("android.resource://"+context.getPackageName()+"/"+R.raw.iphone_5_original);
Intent intent1 = new Intent(context,WelcomeActivity.class);
intent1.putExtra("activityFrom", "notificationAlarm");
PendingIntent activity = PendingIntent.getActivity(context,NOTIFICATION_ID + 1, intent1,  PendingIntent.FLAG_UPDATE_CURRENT);
 notification.setLatestEventInfo(context, "hello","", activity);
notification.number = 1;
manger.notify(notificationId, notification);
    }catch (Exception e) {
    // TODO: handle exception
     e.printStackTrace();
           }
       }   

【问题讨论】:

标签: android time fixed alarms


【解决方案1】:

// 联系 SyncBroadcast.class,它可以是一个活动或广播接收器或服务

 Intent intent = new Intent(this,ContactsSyncBroadcast.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
                0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager =  (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,10*60*1000,10*60*1000, pendingIntent);

警报每 10 分钟触发一次。

【讨论】:

  • 我想设置闹铃持续时间而不是每 10 分钟连续重复闹铃,我清楚了吗???
猜你喜欢
  • 1970-01-01
  • 2016-09-27
  • 2017-04-07
  • 1970-01-01
  • 2018-08-01
  • 2019-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多