1. 브로드캐스트 리시버는 반드시 새로운 java파일을 만들어 코딩해야 하나요?  

    MainActivity에서 onRecieve() 클래스를 밑에 붙여서 코딩하면 안되는건지 궁금합니다


2. 브로드캐스트 리시버를 이용해 전원이 켜졌을경우 노티피케이션 알림을 설정하려고 하는데요



    public class Receiver extends Activity {

NotificationManager notiManager;

    Vibrator vibrator;

private int notiHour,notiMin;

private long notiFlag;


public void onReceive(Context context, Intent intent) {               

        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {      

       

        //notiHour,notiMin 불러오기-------------------------------------------------------- 

        SQLiteDatabase db = null;

      if (db == null) {

      db = openOrCreateDatabase(

      "sqlite_todo.db", 

      SQLiteDatabase.CREATE_IF_NECESSARY, 

      null);

      }

     

     

          Cursor c = db.rawQuery("SELECT * FROM notiTime  ORDER BY _id ASC;", null);

     

     

      c.moveToFirst();

     

      if(c.getCount() == 0){

      notiHour = 12;

      notiMin = 0;

      }

      else{

      notiHour = c.getInt(1);

      notiMin = c.getInt(2);

      }

     

      c.close();

     

      if(db != null) {

      db.close();

      }

      //----------------------------------------------------------------------------------

       

            

        //Notification Handler 설정

    Calendar cal1 = Calendar.getInstance();

            Calendar cal2 = Calendar.getInstance();

                

            cal1.set(Calendar.HOUR_OF_DAY, notiHour);

            cal1.set(Calendar.MINUTE, notiMin);

            cal1.set(Calendar.SECOND, 0);

                

            

            if(cal1.getTimeInMillis() > cal2.getTimeInMillis()) //노티 타임이 지나지 않았을때

                notiFlag = cal1.getTimeInMillis() - cal2.getTimeInMillis(); // 노티타임까지 남은 시간을 계산하여 notiFalg에 넣는다

            else                                                //노티 타임이 지난 이후일때

            notiFlag = cal1.getTimeInMillis() - cal2.getTimeInMillis() + (24 * 60 * 60 * 1000); // 내일 노티타임까지 남은 시간을 계산하여 넣는다


            

            handler.sendEmptyMessageDelayed(1, notiFlag);

            

            

             

        }

    

}


//일정 시간 후에 알림을 발생시킬 핸들러

Handler handler = new Handler(){

 public void handleMessage(android.os.Message msg) {

 

 

  Calendar cal = Calendar.getInstance();

 

 

  Notification noti = new Notification(R.drawable.ic_launcher//알림창에 띄울 아이콘

           , "오늘의 일정입니다 [Do.NOTE]", //간단 메세지

           System.currentTimeMillis()); //도착 시간

  

  noti.defaults = Notification.DEFAULT_SOUND;

  noti.flags = Notification.FLAG_ONLY_ALERT_ONCE;

  noti.flags = Notification.FLAG_AUTO_CANCEL;

  

  Intent intent = new Intent(Receiver.this, Scheduler.class);

  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  PendingIntent pendingI = PendingIntent.getActivity(Receiver.this, 0, intent, 0);

  noti.setLatestEventInfo(Receiver.this, "Do.NOTE", "노티 메시지 TEST" , pendingI);

  

  //알림창 띄우기(알림이 여러개일수도 있으니 알림을 구별할 상수값, 여러개라면 상수값을 달리 줘야 한다.)

  

  

  if(cal.get(Calendar.HOUR_OF_DAY) == notiHour && cal.get(Calendar.MINUTE) == notiMin){

 notiManager.notify(1, noti);

 //진동주기(** 퍼미션이 필요함 **)

 vibrator.vibrate(1000); //1초 동안 진동

  }

  

  //사용자가 노티를 확인하지 않았을 경우를 대비, 재귀적으로 내일 노티를 바로 설정해준다.

  //Notification Handler 설정


  handler.sendEmptyMessageDelayed(1, 24 * 60 * 60 * 1000);


  

  

 }

};

}



이런식으로 코딩했는데 알림이 안울리네요... 왜 그런걸까요?..