ccaring
ccaring

Reputation: 43

Android SMS Broadcast Receiver

Register BroadcastReceiver for SMS_RECEIVE in Manifest, on Android 4.2 my broadcast receiver is called even when app is closed (from recent also). But on Android 7.0, its called when app is running or is in recent, if app is closed it is not being called. I tried to use service and registered Broadcast inside Service still same scenario.

My Receiver is:

 <receiver
            android:name=".BroadcastReceiver.SMSBroadcastReceiver"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.BROADCAST_SMS">
            <intent-filter android:priority="999">
                <category android:name="android.intent.category.DEFAULT" />
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>

Is something missing, or any other way, or now its how it will work?

Upvotes: 1

Views: 824

Answers (2)

ariochdivij666
ariochdivij666

Reputation: 406

https://developer.android.com/guide/components/broadcasts provides the following information:

Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-declared receivers. If your app targets API level 26 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that do not target your app specifically). You can still use a context-registered reciever when the user is actively using your app.

There is also a video about declaring static services/receivers in the manifest.

You probably need to update the code to use job scheduler or work manager. Google i/o was full of work manager videos.

Upvotes: 1

Ferhat Erg&#252;n
Ferhat Erg&#252;n

Reputation: 135

I think you are missing runtime permissions. It was added after Android 6.0 check this .

Upvotes: 0

Related Questions