2010-09-09 76 views
2
public class Alarm extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Intent intent = new Intent(this, AlarmReceiver.class); 

     PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, 
     intent, PendingIntent.FLAG_ONE_SHOT); 

     AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
     alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000), pendingIntent); 
     Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show(); 
    } 
} 

报警在Android中

public final class AlarmReceiver extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show(); 
    } 
} 

后10秒是gettign敬酒报警worke..but没有默认的声音?如何获得声音的,而不是在的TOA Android的报警,我怎样才能显示对话..?

回答

4

AlarmManager与声音无关。您可能会将AlarmManager与闹钟应用混淆。欢迎您通过您的BroadcastReceiver播放声音,尽管我没有尝试过。

+0

CommonsWare .. how can play sound via broadcastReceiver ..?please help me。 – 2010-09-09 13:15:58

0
NotificationManager nm; 
@Override 
public void onReceive(Context context, Intent intent) { 
    nm = (NotificationManager) context.getSystemService(
     Context.NOTIFICATION_SERVICE); 
    CharSequence from = "Check your.."; 
    CharSequence message = "It's time !"; 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
     new Intent(), 0); 
    Notification notif = new Notification(R.drawable.ic_launcher, 
     "ut text", System.currentTimeMillis()); 
    notif.setLatestEventInfo(context, from, message, contentIntent); 
    notif.defaults |= Notification.DEFAULT_SOUND; 
    notif.flags |= Notification.FLAG_AUTO_CANCEL; 
    nm.notify(1, notif);