shounakmulay / Telephony

Flutter plugin for telephony features like query device sms directory, listen for incoming messages, retrieve various network parameters, etc.
https://telephony.shounakmulay.dev
MIT License
138 stars 126 forks source link

Listening to incoming SMS not working #114

Closed bzark closed 2 years ago

bzark commented 2 years ago

I cloned the repo, built it using Android Studio and installed the app on my OnePlus 9 Pro and when I send a text message to my phone it doesn't receive it in the app. Permissions where accepted on first launch. What is the issue?

karlreginaldo commented 2 years ago

I have the same problem.

bzark commented 2 years ago

@shounakmulay any insight or things we can try to see what the issue is?

shounakmulay commented 2 years ago

Hey @bzark seems like this could be a battery optimization issue. Have a look at #115

bzark commented 2 years ago

I tried it on three different phone all running different versions of Android. Also I'm not even testing background, this is not working when the app is actively the foreground app.

bzark commented 2 years ago

I turned battery optimization off for the example app and then ran it. Still not receiving notifications in the app when it is foreground.

bzark commented 2 years ago

@shounakmulay @karlreginaldo

I figured out the issue, has nothing to do with battery optimization. It has to do with what SMS client has the highest priority and it looks like Google has been maxing out that value so you cannot override their default messaging client. I even set MySmsReceiver to the same priority value 214748364 but Googles app still shows up as receiver #0.

C:\tmp\code\Telephony>adb shell cmd package query-receivers --brief -a android.provider.Telephony.SMS_RECEIVED 5 receivers found: Receiver #0: priority=2147483647 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false com.google.android.apps.messaging/.shared.receiver.ConfigSmsReceiver Receiver #1: priority=9999999 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false com.example.smsreceiver/.MySmsReceiver Receiver #2: priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false com.google.android.gms/.chimera.GmsIntentOperationService$GmsExternalReceiver Receiver #3: priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false com.lge.email/.receiver.SmsReceiver Receiver #4: priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false com.example.sms/com.shounakmulay.telephony.sms.IncomingSmsReceiver

github-actions[bot] commented 2 years ago

Issue marked stale due to no activity.

Datarmanatar commented 10 months ago

the reason it doesn't work is because google messenger, which is default for android, doesn't send forward the messages. i downloaded and set Textra as default messaging app, and now it works