Override default android messaging application

后端 未结 3 1772
小鲜肉
小鲜肉 2021-01-01 06:27

I want to override the default android messaging application. If I receive a sms or mms I want to send that to email but i don\'t want any notification on phone. So basica

相关标签:
3条回答
  • 2021-01-01 07:10

    There isn't a "default application" in the way you're thinking. The way applications are dispatched in Android is through Intents. An application wil use an IntentFilter to identify that it can handle specific types of Intents. What you're looking for is a BroadcastReceiver that can handle the SMSReceived intent. That will allow your application to be notified when an SMS is received. In order to hide the notification, you will need to mark the SMS as read using the SMS ContentProvider. That will clear the notification out of the notification tray. There is no way to hide a message from the default messaging application unless you delete the message from the SMS ContentProvider. Check out this link for how to get started with BroadcastReceivers.

    0 讨论(0)
  • 2021-01-01 07:19

    There is a way to block the message from going to the the default messaging app. If you set the priority of your BroadcastReceiver up high enough (we use 100) and call abortBroadcast to block the intent from being picked up by any lower priority BroadcastReceivers. It will only work if the intent broadcast is ordered, something that is out of our control. But it turns out that the SMS_SENT broadcast is ordered, and I suspect the MMS_SENT broadcast is as well.

    0 讨论(0)
  • 2021-01-01 07:24

    If you sent priority of your BroadcastReceiver high enough, your application is the first one receiving the message, BEFORE the message is stored in the database. I guess the solution would be to store the message in the database yourself and call abortBroadcast();, but I didn't try this myself, yet.

    Good luck!

    0 讨论(0)
提交回复
热议问题