簡単なアラームトリガーを作成しようとしています。アラームが鳴ると、簡単な音のアラームが鳴るはずです。しかし、アラームは鳴らず、何も起こりません。今、私はどこを間違えているのかわかりません-それは時代ですか?意図?レシーバー?
私がAlarmManagerを使用しているクラス
package com.example.prva;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
public class Meni_Splash extends Activity{
Calendar c = Calendar.getInstance();
private int hour = c.get(Calendar.HOUR_OF_DAY);
private int minute = c.get(Calendar.MINUTE);
int milivreme;
int milipicker;
long sveskupa;
int hoursad;
int minutesad;
protected boolean timeactive = true;
Handler h=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
h.post(new Runnable(){
@Override
public void run() {
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
TextView text = (TextView) findViewById(R.id.textDate);
text.setText(currentDateTimeString);
h.postDelayed(this, 1000);
}
});
final TimePicker picker = (TimePicker) findViewById(R.id.timePicker);
final TextView text = (TextView) findViewById(R.id.texttime);
picker.setIs24HourView(true);
picker.setCurrentHour(hour);
picker.setCurrentMinute(minute);
Button btnt = (Button) findViewById(R.id.buttontime);
btnt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
hoursad = picker.getCurrentHour();
minutesad = picker.getCurrentMinute();
milipicker = (((hoursad) * 60 * 60 * 1000) + ((minutesad) * 60 * 1000));
text.setText(new StringBuilder().append(hoursad).append(":").append(minutesad).append( "Trenutno vrijeme u milisekundama : ").append(System.currentTimeMillis()).append(" vrijeme izabrano u milisekundama sve skupa ").append(milipicker));
}
});
Button btnalarm = (Button) findViewById(R.id.btnalarm);
btnalarm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
hoursad = picker.getCurrentHour();
minutesad = picker.getCurrentMinute();
milivreme = (((hour)* 60 * 60 * 1000)+ ((minute) * 60 * 1000));
milipicker = (((hoursad) * 60 * 60 * 1000) + ((minutesad) * 60 * 1000));
sveskupa = milipicker - milivreme;
Intent intent = new Intent(Meni_Splash.this, AlarmReceiver.class);
PendingIntent pendingintent = PendingIntent.getActivity(Meni_Splash.this, 2, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + sveskupa, pendingintent);
}
});
Button btnv = (Button) findViewById(R.id.buttonv);
btnv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Meni_Splash.this, button.class));
}
});
}
}
AlarmReceiverクラス:
package com.example.prva;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
public class AlarmReceiver extends Activity {
protected MediaPlayer MPAlarm;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
MPAlarm = MediaPlayer.create(this, R.raw.splash);
MPAlarm.start();
}
};