1

I'm working on a utility application in which when an SMS is received with a specific message I need to send a reply message. To know the sms_received event i used a broadcast receiver. Below it the code of it in the manifest file.

<receiver
    android:name=".SMSReceiver"
    android:enabled="true"
    android:exported="true"

    android:permission="android.permission.BROADCAST_SMS">
    <intent-filter android:priority="900">
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

I had defined runtime permissions and the broadcast receiver is triggering when sms is received and executing its task and everything working fine as expected. But the problem is it stops working after some time. Maybe the Android device is killing my application process. I know this by going to app-info and there the force stop button is disabled. which means no process related to the app is running.

I had another application on same mobile in which I used the FCM and its process is running for several days. not only this many apps like whatsapp, telegram working for several days even those application not opened. I see this by opening app-info and there i seen force-stop button enabled.

how those apps working in background for several days? what I'm missing in my application? how to run my broadcast receiver for several days? any suggestions are greatly appreciated, thanks in advance.

Venkat
  • 384
  • 1
  • 16
  • With FCM your app process is NOT running for several days. The OS will actually restart your app and launch the BroadcastReceiver associated with FCM messages when one comes in. That's one of the points of a BroadcastReceiver- they're meant to be an entry point to your app. – Gabe Sechan Sep 02 '23 at 06:14
  • Also, why are your putting the BROADCAST_SMS permission there? You can't get that permission unless you're pre-installed, that permission is not allowed for 3rd party apps, as per the permissions documentation – Gabe Sechan Sep 02 '23 at 06:17
  • @GabeSechan Thanks for resposne. I'm Using BROADCAST_SMS because android studio show me a minor warning of `BroadcastReceivers that declare an intent-filter for SMS_DELIVER or SMS_RECEIVED must ensure that the caller has the BROADCAST_SMS permission, otherwise it is possible for malicious actors to spoof intents` But here my question is **how to make the broadcast receiver alive?** – Venkat Sep 02 '23 at 11:35

0 Answers0