3

In IceCreamSandwch and JellyBean the default trigger limit is 30 SMSes from any package within a 30 minute period. This used to be 100 SMSes in an hour, which wasn't such a problem but now we need to be careful how many messages our app sends.

Having Googled and searched StackOverflow I cannot find any sample of how a package can query it's current limit, is this something that we would have to maintain in our own package or is there a hidden method somewhere in the Android API?

If our own package has to maintain a count of it's current limit how would you propose to go about it?

Apqu
  • 4,880
  • 8
  • 42
  • 68

1 Answers1

3

From one of Al Sutton's G+ post:

The limits can be overridden by OEMs either by changing the source code or using the secure settings Settings.Secure.SMS_OUTGOING_CHECK_MAX_COUNT and Settings.Secure.SMS_OUTGOING_CHECK_INTERVAL_MS, so you may see users presented with a dialogue asking them to confirm the SMS being sent is OK even if you comply with the #AOSP default rate limits.

So you might give a try to Settings.Secure.SMS_OUTGOING_CHECK_MAX_COUNT and Settings.Secure.SMS_OUTGOING_CHECK_INTERVAL_MS.

shkschneider
  • 17,833
  • 13
  • 59
  • 112
  • 1
    Those fields are hidden, but if you pass the field names as lowercase Strings to `Settings.Secure.getInt()`, it should work, judging by the source code. – Mike M. Jan 06 '15 at 16:36
  • Afraid that I just get a SettingNotFoundException, I guess they are not publicly visible? – Apqu Jan 06 '15 at 16:38
  • 1
    @Tur I just successfully tested it. Make sure you've got the names exactly correct, and that they're lowercase. – Mike M. Jan 06 '15 at 16:45
  • Hmm, must be doing something wrong then, trying: Settings.Secure.getInt(contentResolver, "sms_outgoing_check_max_count"); – Apqu Jan 06 '15 at 16:45
  • @MikeM. If you want to post an answer I can mark it as correct? – Apqu Jan 06 '15 at 16:54
  • 1
    @Tur I appreciate the offer, but we've not got your issue completely solved yet. shkschneider should get the credit, anyway, if they'd like to amend their answer. :-) What are you testing on? Specifically, what kind of device, and which Android version? – Mike M. Jan 06 '15 at 17:02
  • @MikeM. Android KitKat 4.4 on an LG G2, is my code the same as what your test code looked like? – Apqu Jan 06 '15 at 18:19
  • @Tur Yep, pretty much, except I was lazy; copied/pasted: `Settings.Secure.getInt(getContentResolver(), "SMS_OUTGOING_CHECK_MAX_COUNT".toLowerCase())`. I'm on a Galaxy S4, ver 4.4.4. – Mike M. Jan 06 '15 at 18:36
  • @Tur One last thing I can think of: the `getInt()` method throws a `SettingNotFoundException` if the setting parse throws a `NumberFormatException`, so you might try `getString()` instead, and see if it returns. I can't find anything about LG restricting those settings. – Mike M. Jan 06 '15 at 18:42
  • 1
    @MikeM. Thanks for all your help, as a string it returns null. I think that these settings must be hidden for "normal" apps? – Apqu Jan 07 '15 at 08:13
  • @Tur My test was with just a basic app; no special permissions. Maybe that particular device doesn't have limits set? I guess you could try sending a huge number of texts on it; see if you get the limit message. You might also try retrieving the setting again, and keep an eye on your logcat. Looking at the source, there are a few different log prints that might occur and could give a clue as to what's happening. – Mike M. Jan 07 '15 at 08:45
  • @MikeM. Tried again with a different phone and still getting null result for both setting values, nothing appearing in logcat i'm afraid, I could try sending a large number of sms on both devices but I am almost certain the second device (fresh stock rom) would have the limit set somewhere? – Apqu Jan 07 '15 at 14:22
  • @Tur Hmm. Bummer. That may very well be the norm, and I just have a super-special phone. :-) I'm not sure what else to tell ya at this point. You might try a phone from a different provider, if your second test device wasn't. The provider ultimately determines those settings. – Mike M. Jan 07 '15 at 14:27
  • Lol, most probably ;-) Once I hit the limit on the second phone I get an info logcat: I/[SMS_LF]﹕ sendTextMessage(), SmsManager --> IccSmsInterfaceManager but that's about all. Back to the drawing board it is then, thanks for all your help though, very much appreciated! – Apqu Jan 07 '15 at 14:29
  • Sorry that did not work. As a private value, this solution is not reliable, but that's the only way I'm aware off to achieve what you asked. – shkschneider Jan 07 '15 at 14:33
  • 1
    Two years later, and I think I may have stumbled upon the reason this wasn't working for @Apqu. At some point around KitKat, those `Settings` moved from `Settings.Secure` to `Settings.Global`. The constants' `String` values are still the same, though. We might've just had the OP looking in the wrong place for their device. Anyhoo, just an FYI, if you wanna update your info. Cheers! – Mike M. Mar 24 '17 at 23:29