Android BroadcastReceiver on startup - keep running when Activity is in Background

后端 未结 5 642
眼角桃花
眼角桃花 2020-11-22 05:34

I\'m monitoring incoming SMSs.

My app is working perfectly with a BroadcastReceiver. However it is working from an Activity and would like to keep the <

5条回答
  •  自闭症患者
    2020-11-22 05:56

    use this code and also mention the broadcast in Manifest also:

    public class BootService extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
                Toast.makeText(context, "Boot Completed", Toast.LENGTH_SHORT).show();
                //write code here
            }
        }
    }
    

提交回复
热议问题