Start application without activity, my Broadcast Receiver not work

后端 未结 5 1108
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 13:14

In my app, I have a Broadcast Receiver for catching the message sent to my phone



        
5条回答
  •  臣服心动
    2020-12-19 13:52

    This is because Android OS does not allow BroadcastReceiver to receive some important broadcast(android.provider.Telephony.SMS_RECEIVED must be one of it) if the app´s process is not alive.It was designed to against the evil apps. If you have an activity running,your process is alive and so your receiver is allowed to receive the broadcast.

    I think you can make a transparent activity and use startService to start a service in background,then finish the activity.As your service is running ,your process is alive,so the Android OS will let you to receive the broadcast.

提交回复
热议问题