public class WorkOrderAlarmReceiver extends BroadcastReceiver {
 private final static int NOTIFICATION_ID = 0;
 private String prefs_name = "pref";
 private int mode = Context.MODE_PRIVATE;

 @Override
 public void onReceive(Context context, Intent intent) {
  
  String action = intent.getAction();
  if(action.equals(android.content.Intent.ACTION_BOOT_COMPLETED)){
   SharedPreferences prefs = context.getSharedPreferences(prefs_name, mode);
   long time = prefs.getLong("jalarm_getTime", 0);
   long time2 = prefs.getLong("alarm_getTime", 0);
   PendingIntent sender = PendingIntent.getBroadcast(context, 1, intent, 0); // getbroadcast로 수신
   AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // 알람매니저 사용하기 위해 객체 생성
   am.set(AlarmManager.RTC_WAKEUP, time, sender); // 알람매니저 셋팅
   PendingIntent sender2 = PendingIntent.getBroadcast(context, 2, intent, 0);
   am.set(AlarmManager.RTC_WAKEUP, time2, sender2); // 알람매니저 셋팅
  }


 

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.workoderalarm" android:versionCode="1"
 android:versionName="1.0">
 <uses-sdk android:minSdkVersion="8" />

 <application android:icon="@drawable/icon" android:label="@string/app_name"
  android:debuggable="true">
  <activity android:name=".WorkOrderAlarm" android:label="@string/app_name">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
  <receiver android:name=".WorkOrderAlarmReceiver"
   android:process=":remote" android:enabled="true" android:exported="true">
   <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
   </intent-filter>
  </receiver>
 </application>
 <uses-permission android:name="android.permission.VIBRATE">
 </uses-permission>
 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
 </uses-permission>
</manifest>

ACTION_BOOT_COMPLETED를 사용하여 부팅후에 알람이 등록되게 해 보았습니다.

여기서 if(action.equals(android.content.Intent.ACTION_BOOT_COMPLETED)){
이부분에서 NullPointerException이 발생합니다. 이 에러가 왜 나는지..사용방법은 제대로 맞는지 궁금합니다.

고수님들 도와주세요..ㅠㅠ 혹시나 이방법말고 폰의 전원을 껐다 커도 알람이 울리도록 하는 방법이 있으면 조언좀 해주세요~