我为下载数据创建了一个意图服务,我想重复广播接收和警报管理器。我如何调用我的意图服务?我尝试了这个但没有工作....
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Don't panik but your time is up!!!!.",
Toast.LENGTH_LONG).show();
// Vibrate the mobile phone
Vibrator vibrator = (Vibrator)
context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500);
intent.setData(Uri.parse("http://www.mysite.net/LEDstate.txt"));
intent.putExtra("urlpath", "http://www.mysite.net/LEDstate.txt");
//startService(intent);
context.startService(new Intent(context, DownloadService.class));
}
公共类 AlarmActivity 扩展 Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startAlert(View view) {
EditText text = (EditText) findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
//alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
// + (i * 1000),pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
,(i*1000),pendingIntent);
// alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar
// .getTimeInMillis(), intervals, pendingIntent);
Toast.makeText(this, "Alarm set in " + i + " seconds",
Toast.LENGTH_LONG).show();
}