In my app, I have a Broadcast Receiver for catching the message sent to my phone
<receiver
android:name="com.qmobile.ows.SMS_Receiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
If I start app with activity GUI, the BroadCast Receiver works normally.
I want to start my application without activity and do not show icon app, so I remove this code below from my activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
And after that, Broadcast Receiver do not work.
Please help me solve this problem.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With