0

有许多扩展 BroadcastReceiver 以通过意图从另一个类激活的类示例。类也从 BroadcastReceiver 扩展而来,它在诸如接收到的文本消息之类的事件中被激活。我的问题是如何在到达指定时间时激活扩展 BroadcastReceiver 的类,例如上午 8:20 没有意图。不知道我解释了没有。

4

2 回答 2

0

As mentioned in this question:

Android Alarm Manager with broadcast receiver registered in code rather than manifest

You will need to use a pendingintent for this. I am not sure why you don't want to use an intent - could you explain further?

于 2013-09-30T01:36:44.437 回答
0

我有一个项目,我有一个名为 AlarmReceiver 的独特类,我想在给定时间或晚上 9:01 显示敬酒。具体来说,类如下:

package org.secure.sms;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.AlarmManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

 public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
     Calendar calendar = Calendar.getInstance();
  int mYear = calendar.get(Calendar.YEAR);
  int mMonth = calendar.get(Calendar.MONTH);
  int mDay = calendar.get(Calendar.DAY_OF_MONTH);
  int mHour = calendar.get(Calendar.HOUR_OF_DAY);
  int mSec = calendar.get(Calendar.MINUTE);
  if((mHour == 9 && mSec == 1) { 
    Toast.makeText(context, "Alarm Receiver message", Toast.LENGTH_SHORT).show();
  }
}
}
于 2013-09-30T19:23:13.017 回答