Невозможно остановить сигнал вызова в Android
Я пытаюсь в течение одной минуты включить будильник в приложении для Android. Но будильник звонит бесконечно. Почему?
Предложения пожалуйста
Спасибо за ваше драгоценное время!..
Пожалуйста, найдите мой logcat и источники для справки
Logcat
05-25 15:23:01.616: D/Ringtone(1657): HWDrmException :nativeCreateDrmContent() returned JNI_DRM_FAILURE65538
05-25 15:23:15.546: E/MediaPlayer(1657): internal/external state mismatch corrected
05-25 15:23:17.486: E/MediaPlayer(1657): internal/external state mismatch corrected
05-25 15:23:21.316: E/MediaPlayer(1657): internal/external state mismatch corrected
AndroidAlarmService.java
public class AndroidAlarmService extends Activity {
private PendingIntent pendingIntent;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent myIntent = new Intent(AndroidAlarmService.this, RepeatingAlarm.class);
pendingIntent = PendingIntent.getBroadcast(AndroidAlarmService.this, 0, myIntent, 0);
AlarmManager aM = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar c=Calendar.getInstance();
c.set(Calendar.HOUR, 2);
c.set(Calendar.MINUTE, 45);
c.set(Calendar.SECOND, 0);
PendingIntent pi = PendingIntent.getBroadcast(AndroidAlarmService.this, 0, myIntent, 0);
aM.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), AlarmManager.INTERVAL_DAY,pendingIntent);
}
}
RepeatingAlarm.java
public class RepeatingAlarm extends BroadcastReceiver
{
MediaPlayer mRingtoneLooper;
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context,"Alarm Started.....", Toast.LENGTH_LONG).show();
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final Ringtone r = RingtoneManager.getRingtone(context, notification);
Timer star_ringtone = new Timer();
while(r!=null){
if(!r.isPlaying()){
r.play();
}
star_ringtone.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
r.stop();
}
},60000);
}
// Vibrate the mobile phone
Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vb.vibrate(1000);
}}