How to check if Alarm have been set and running

前端 未结 2 1661
青春惊慌失措
青春惊慌失措 2021-01-06 15:17

I have a receiver that start after phone boot like this:


            
                       


        
2条回答
  •  無奈伤痛
    2021-01-06 15:52

    The only thing you can do is when the user install the app and open it the first time you can set a flag in the SharedPreference that tells you if the Alarm is set or not if its not set set the Alaram .

    in your main Activity check in the onCreate method

    SharedPreferences spref = getSharedPreferences("TAG", MODE_PRIVATE);
    
     Boolean   alaram_set = spref.getBoolean("alarm_set_flag", false);  //default is false
    
    if(!alaram_set){
    //create your alarm here then set the flag to true
    
     SharedPreferences.Editor editor = spref.edit();
            editor.putBoolean("alarm_set_flag", true); // value to store
            editor.commit();
    }
    

提交回复
热议问题