我对android开发感兴趣,我想知道是否有可能每年在特定时间播放一些歌曲在特定时刻在android中如何做。谢谢!
public class AlarmActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);
Intent myIntent = new Intent(AlarmActivity.this , MyBroadcastReceiver.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(AlarmActivity.this, 0, myIntent, 0);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 02);
cal.set(Calendar.MINUTE, 18);
cal.set(Calendar.SECOND, 55);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60000 , pendingIntent); //set repeating every year
}
}
广播:
public class MyBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Broadcast Received.", Toast.LENGTH_LONG).show();
// Vibrate the mobile phone
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
}
}
答案 0 :(得分:0)
检查official documentation以了解如何设置闹钟。
至于您的具体目标,您可以在当前铃声响起时为下一年设置新闹钟。
答案 1 :(得分:0)
undefined
希望这会有所帮助..