How to listen to new Sms in Android

2019-06-09 01:32发布

I am trying to listen to new sms(Message) with the help of BroadcastReceiver, but it is keep on listening to messages throughout the application and even after closing the app, so what to do??

Whether there is any other way to listen to sms or latest method as IntentReceiver kind of solutions(available over I-net) are deprecated and not working

标签: android sms
3条回答
何必那么认真
2楼-- · 2019-06-09 01:40

If you register an Activity or Service as a BroadcastReceiver in the AndroidManifest.xml file, then the broadcast notifying it of the message will be received even if your Activity isn't open. If you only want your app to receive a notification that an SMS has arrived ONLY when it is open, you need to register a BroadcastReciever for SMS messages in the onResume method, using one of the registerReceiver() methods and then un-register it in your Activity's onPause() method using unregisterReceiver(). That way your app will stop listening for SMS messages when it isn't open.

查看更多
老娘就宠你
3楼-- · 2019-06-09 01:44

You need to dynamically register and unregister your BroadcastReceiver. So, when you detect that your application gets closed, just unregister your receiver. See more here.

查看更多
手持菜刀,她持情操
4楼-- · 2019-06-09 01:51

Hey Ankit, just check this out, is this what u needed, .............

https://github.com/vivdub/DynamicSMSReceiver

Thanks

查看更多
登录 后发表回答