2013-03-26 107 views
-4

如何在Android中播放特定時間段的鬧鐘通知(例如連續播放10分鐘)?如何播放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(); 
      } 
     } 
+1

[歡迎來到Stackoverflow](http://stackoverflow.com/faq#dontask) – RobinHood 2013-03-26 10:38:07

+0

實際上是什麼問題? – Gunaseelan 2013-03-26 10:43:29

回答

0

//聯繫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分鐘。

+0

我想設置鬧鈴響鈴持續時間不會每10分鐘連續重複一次鬧鈴我清楚嗎? – user2099162 2013-03-26 12:54:46