소스
public static void registerAlarm(Context context)
{
Intent intent = new Intent(context, AndroidBradcastReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
try
{
// 내일 아침 8시 10분에 처음 시작해서, 24시간 마다 실행되게
Date tomorrow = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2012-09-01 11:25:00");
long test = tomorrow.getTime();
AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, tomorrow.getTime(), 1000, sender);
} catch (ParseException e)
{
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class AndroidBradcastReceiver extends BroadcastReceiver{
private String ACTIONBOOTCOMPLETED = "android.intent.action.ACTION_BOOT_COMPLETED";
private String ACTIONSCREENOFF = "android.intent.action.ACTION_SCREEN_OFF";
private String ACTIONPOWERCONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
private String TAG = "AndroidAlramTestActivity";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(AndroidAlramTestActivity.INNER_PUSH))
{
Toast.makeText(context, "sdf", Toast.LENGTH_SHORT).show();
Log.d(TAG, "INNER_PUSH");
//핸드폰이 부팅이 되었을때
}else if(intent.getAction().equals(ACTIONPOWERCONNECTED ))
{
Log.d(TAG, "ACTIONPOWERCONNECTED");
Toast.makeText(context, "핸드폰이 부팅이 되었을때", Toast.LENGTH_SHORT).show();
//스크린이 오프 되어있을때
}else if(intent.getAction().equals(ACTIONSCREENOFF))
{
Log.d(TAG, "ACTIONSCREENOFF");
Toast.makeText(context, "스크린이 오프 되어있을때", Toast.LENGTH_SHORT).show();
//외부 전원이 연결되어있을때
}else if(intent.getAction().equals(ACTIONBOOTCOMPLETED))
{
Log.d(TAG, "ACTIONBOOTCOMPLETED");
Toast.makeText(context, "외부 전원이 연결되어있을때", Toast.LENGTH_SHORT).show();
}else
{
Toast.makeText(context, "sdfsdfsdfsfsdfsf", Toast.LENGTH_SHORT).show();
Log.d(TAG, "INNER_PUSH");
}
}
androidManifest.xml
<activity android:name=".AndroidBradcastReceiver">
<receiver android:name="AndroidBradcastReceiver" android:process=":remote">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"></action>
<action android:name="android.intent.action.ACTION_SCREEN_OFF"></action>
<action android:name="android.intent.action.ACTION_BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</activity>
위와 같이 되어있는데요
Date tomorrow = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2012-09-01 11:25:00");
long test = tomorrow.getTime();
AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, tomorrow.getTime(), 1000, sender);
이부분을 날짜를 오늘짜와 시간을 지금 시간에 2분후로바꾸고 1초후에 알림이 되도록했는데
onReceive가 호출이 안되나요
어떻게하면 onReceive 호출이 가능할까요?




Receiver를 AndroidMenifest.xml에 등록하셨는지 확인해 보세요.