简体   繁体   English

Android - 以编程方式禁用文本消息通知

[英]Android - Disable text message notifications programmatically

I'm working on an application that handles text messages. 我正在处理一个处理短信的应用程序。 This is a personal application and I do not plan to release it, however it's basically going to allow me to share my text messages (and phone number) between numerous devices through the internet. 这是一个个人应用程序,我不打算发布它,但它基本上允许我通过互联网在众多设备之间共享我的短信(和电话号码)。 It's a fun learning project too as a first application, and I've done quite a lot. 作为第一个应用程序,它也是一个有趣的学习项目,而且我做了很多。

However the annoying part is the text-message popup that my device gets when receiving a message. 然而令人讨厌的部分是我的设备在接收消息时获得的文本消息弹出窗口。 I love it when I'm using the device, and I could always just go into the options and disable the popup when I'm not planning on using the device, but I'm a very, very forgetful person and turning it back on wont always happen. 我喜欢它,当我使用该设备时,我可以随时进入选项并在我不打算使用该设备时禁用弹出窗口,但我是一个非常非常健忘的人并将其重新打开永远不会发生。 Then I'll never reply to messages. 然后我永远不会回复邮件。

Basically I want to programmatically interrupt (or not even notify) my default messaging application of the text message, however I still want it to be logged in my messaging history. 基本上我想以编程方式中断(或甚至不通知)我的文本消息的默认消息传递应用程序,但是我仍然希望它记录在我的消息传递历史记录中。 So the message can't just be "discarded". 所以消息不能被“丢弃”。 This should only happen of-course while my applications service is running. 这应该只在我的应用程序服务运行时发生。

I've been searching through the android API for quite some time and I just can't seem to figure this out, is it possible and if so can you link me to the proper place in the API to begin? 我一直在搜索android API很长一段时间,我似乎无法弄明白,是否有可能,如果是这样,你可以将我链接到API的正确位置开始吗?

Basically I want to programmatically interrupt (or not even notify) my default messaging application of the text message... 基本上我想以编程方式中断(或甚至不通知)我的短信消息应用程序...

This isn't possible. 这是不可能的。

Assuming by "interrupt" you mean to prevent the default SMS app from issuing its Notification, you can no more do this with the default app than you could with any other app that you don't control. 假设通过“中断”意味着阻止默认SMS应用程序发出其通知,您可以使用默认应用程序执行此操作,而不是使用您无法控制的任何其他应用程序。

Additionally, as the default SMS app responds to the SMS_DELIVER_ACTION broadcast, and it is the only app to receive this broadcast, it wouldn't be possible to "not...notify" the default app of an incoming message. 此外,由于默认SMS应用程序响应SMS_DELIVER_ACTION广播,并且它是唯一接收此广播的应用程序,因此无法“不...通知”传入消息的默认应用程序。 Your app wouldn't even have a chance to abort the broadcast, even if it were possible to do so. 你的应用甚至没有机会中止广播,即使有可能这样做。

(In versions prior to KitKat, it was oftentimes possible to register a Receiver with a high priority for the SMS_RECEIVED_ACTION broadcast, and then abort the broadcast before the native SMS app received it. This is what rajan ks's answer refers to.) (在KitKat之前的版本中,通常可以为SMS_RECEIVED_ACTION广播注册具有高优先级的接收器,然后在本机SMS应用程序接收之前中止广播。这就是rajan ks的回答所指的。)

...however I still want it to be logged in my messaging history. ...但是我仍然希望它记录在我的消息历史记录中。

The default SMS app is responsible for writing all incoming messages to the Provider. 默认的SMS应用程序负责将所有传入的消息写入提供程序。 Even if you were able to prevent the default app from receiving the incoming message, your app would then have to write the message itself. 即使您能够阻止默认应用程序接收传入消息,您的应用程序也必须自己编写消息。 This isn't really possible, either, as the default app is the only one with standard write access to the Provider. 这也是不可能的,因为默认应用程序是唯一具有对Provider的标准写入权限的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM