Android 发送大量短信
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1663514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android sending lots of SMS messages
提问by Robert Parker
I have a app, which sends a lot of SMS messages to a central server. Each user will probably send ~300 txts/day. SMS messages are being used as a networking layer, because SMS is almost everywhere and mobile internet is not. The app is intended for use in a lot of 3rd world countries where mobile internet is not ubiquitous.
我有一个应用程序,它向中央服务器发送大量 SMS 消息。每个用户每天可能会发送约 300 条 txt。SMS 消息被用作网络层,因为 SMS 几乎无处不在,而移动互联网则不然。该应用程序旨在用于许多移动互联网并不普遍的第三世界国家。
When I hit a limit of 100 messages, I get a prompt for each message sent. The prompt says "A large number of SMS messages are being sent". This is not ok for the user to get prompted each time to ask if the app can send a text message. The user doesn't want to get 30 consecutive prompts.
当我达到 100 条消息的限制时,我会收到每条发送消息的提示。提示“正在发送大量短信”。用户每次都被提示询问应用程序是否可以发送短信是不行的。用户不希望得到 30 个连续的提示。
I found this android source file with google. It could be out of date, I can't tell. It looks like there is a limit of 100 sms messages every 3600000ms(1 day) for each application.
我用谷歌找到了这个android源文件。它可能已经过时了,我不知道。看起来每个应用程序每 3600000 毫秒(1 天)有 100 条短信的限制。
/** Default checking period for SMS sent without uesr permit */
private static final int DEFAULT_SMS_CHECK_PERIOD = 3600000;
/** Default number of SMS sent in checking period without uesr permit */
private static final int DEFAULT_SMS_MAX_ALLOWED = 100;
and
和
/**
* Implement the per-application based SMS control, which only allows
* a limit on the number of SMS/MMS messages an app can send in checking
* period.
*/
private class SmsCounter {
private int mCheckPeriod;
private int mMaxAllowed;
private HashMap<String, ArrayList<Long>> mSmsStamp;
/**
* Create SmsCounter
* @param mMax is the number of SMS allowed without user permit
* @param mPeriod is the checking period
*/
SmsCounter(int mMax, int mPeriod) {
mMaxAllowed = mMax;
mCheckPeriod = mPeriod;
mSmsStamp = new HashMap<String, ArrayList<Long>> ();
}
boolean check(String appName) {
if (!mSmsStamp.containsKey(appName)) {
mSmsStamp.put(appName, new ArrayList<Long>());
}
return isUnderLimit(mSmsStamp.get(appName));
}
private boolean isUnderLimit(ArrayList<Long> sent) {
Long ct = System.currentTimeMillis();
Log.d(TAG, "SMS send size=" + sent.size() + "time=" + ct);
while (sent.size() > 0 && (ct - sent.get(0)) > mCheckPeriod ) {
sent.remove(0);
}
if (sent.size() < mMaxAllowed) {
sent.add(ct);
return true;
}
return false;
}
}
Is this even the real android code? It looks like it is in the package "com.android.internal.telephony.gsm", I can't find this package on the android website.
这甚至是真正的android代码吗?看起来它在包“com.android.internal.telephony.gsm”中,我在android网站上找不到这个包。
How can I disable/modify this limit? I've been googling for solutions, but I haven't found anything.
如何禁用/修改此限制?我一直在谷歌搜索解决方案,但我没有找到任何东西。
So I was looking at the link that commonsware.com posted, and I found that the source had actually changed. And so I might still have a shot.
所以我查看了 commonsware.com 发布的链接,我发现源实际上已经改变了。所以我可能还有机会。
int check_period = Settings.Gservices.getInt(mResolver,
Settings.Gservices.SMS_OUTGOING_CEHCK_INTERVAL_MS,
DEFAULT_SMS_CHECK_PERIOD);
int max_count = Settings.Gservices.getInt(mResolver,
Settings.Gservices.SMS_OUTGOING_CEHCK_MAX_COUNT,
DEFAULT_SMS_MAX_COUNT);
mCounter = new SmsCounter(max_count, check_period);
This is getting checkPeriod and maxCount from a settings table. But I don't seem to have access to the same table. That source should be Android 1.1, which is the same I'm using. When I try to import android.provider.Settings.Gservices, I get an error saying that the import can't be resolved.
这是从设置表中获取 checkPeriod 和 maxCount 。但我似乎无法访问同一张桌子。该源应该是 Android 1.1,这与我正在使用的相同。当我尝试导入 android.provider.Settings.Gservices 时,我收到一条错误消息,指出无法解析导入。
What is going on?
到底是怎么回事?
回答by sdtom
Did you try using "import android.provider.Settings;" instead of "import android.provider.Settings.GServices"? (see line 36 of SMSDispatcher.java)
您是否尝试使用“import android.provider.Settings;” 而不是“导入android.provider.Settings.GServices”?(请参阅SMSDispatcher.java 的第 36行)
Also, not sure how much difference it makes, but 3600000 ms is one hournot one day.
另外,不确定它有多大区别,但 3600000 毫秒是一小时而不是一天。
回答by Brandon O'Rourke
Unfortunately I think you only have a few options
不幸的是,我认为你只有几个选择
1) Get root access and alter the settings table directly by doing:
1)通过执行以下操作获取root访问权限并直接更改设置表:
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
sqlite> INSERT INTO gservices (name, value) VALUES
('sms_outgoing_check_interval_ms', 0);
2) Use multiple apps since it's a per app limit
2)使用多个应用程序,因为它是每个应用程序的限制
3) Perhaps take out the battery after you reach the limit? It looks like the limit is stored in memory. I haven't tried this yet though.
3)也许在达到极限后取出电池?看起来限制存储在内存中。不过我还没有试过这个。
回答by Goyuix
This appears to be built into the Android source tree, so the only way to push this change down to the users would be the build your own ROM and have them install it.
这似乎内置在 Android 源代码树中,因此将此更改推送给用户的唯一方法是构建您自己的 ROM 并让他们安装它。
As for ideas on getting around it, why not check for network connectivity first rather than just assuming it doesn't exist. Even if it is not present on a significant majority of devices today, that certainly won't always be the case. Let SMS be the fall back mechanism. If it is the fall back mechanism, you can then prompt the user letting them know that they will be prompted to confirm the level of SMS activity every 100 messages or so. Who knows, they may roam into a Wifi hotspot and have connectivity part of the day too.
至于绕过它的想法,为什么不先检查网络连接而不是假设它不存在。即使它在今天的绝大多数设备上都不存在,但肯定不会总是如此。让 SMS 成为回退机制。如果是回退机制,那么您可以提示用户让他们知道每 100 条左右的消息将提示他们确认 SMS 活动的级别。谁知道呢,他们可能会漫游到 Wifi 热点并在一天中也有连接。
Otherwise, you will get into a game of installing a bunch of other Activities+Intents that can act as silent SMS proxies to get around the limit. Of course, this has its own certain set of undesirable qualities as well and I can hardly believe I just typed/suggested something that evil.
否则,您将陷入安装一堆其他活动+意图的游戏中,这些活动+意图可以充当静默 SMS 代理以绕过限制。当然,这也有其自身的某些不受欢迎的品质,我简直不敢相信我只是输入/建议了一些邪恶的东西。