Java的机器人,如何知道短信发送成功? [英] Java android, how to know if a sms is successfully sent?
问题描述
我怎么知道,如果短信发送成功?
How I can know if a sms is successfully sent ?
我已经检查的文件,但我没有找到一个方法来解决我的问题... 我怎么能知道?
I have checked the documentation, but I did not find a way to fix my problem... How can I know that ?
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",Toast.LENGTH_SHORT).show();
getServerData("http://site.com","id",Id);
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
System.exit(0);
Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
System.exit(0);
Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show();
break;
case SmsManager.STATUS_ON_SIM_UNSENT:
System.exit(0);
Toast.makeText(getBaseContext(), "Message unsent", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
System.exit(0);
Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
System.exit(0);
Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show();
break;
case SmsManager.STATUS_ON_SIM_SENT :
System.exit(0);
Toast.makeText(getBaseContext(), "Message sent", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
//Toast.makeText(getBaseContext(), "SMS delivered", Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
// Toast.makeText(getBaseContext(), "SMS not delivered", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
if(isMobileAvailable(getApplicationContext()) == true){
Toast.makeText(getApplicationContext(), "Reseau mobile: OK !", Toast.LENGTH_LONG).show();
ArrayList<String> parts = (ArrayList<String>) splitInChunks(message, 120);
for (String str : parts) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, str, null, null);
}
getServerData("http://site.com","id",Id);
}else
Toast.makeText(getApplicationContext(), "Reseau mobile: NOK !", Toast.LENGTH_LONG).show();
}
我中庸之道想知道如果我的短信successfuly sended ... tranks你!
I juste want to know if my sms is successfuly sended... tranks you !
推荐答案
添加到@Aexin
Inbox = "content://sms/inbox"
Failed = "content://sms/failed"
Queued = "content://sms/queued"
Sent = "content://sms/sent"
Draft = "content://sms/draft"
Outbox = "content://sms/outbox"
Undelivered = "content://sms/undelivered"
All = "content://sms/all"
Conversations = "content://sms/conversations"
数据库字段
0: _id
1: thread_id
2: address
3: person
4: date
5: protocol
6: read
7: status
8: type
9: reply_path_present
10: subject
11: body
12: service_center
13: locked
<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/1.5_r4/android/provider/Telephony.java" rel="nofollow">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/1.5_r4/android/provider/Telephony.java
@Shuty
<一个href="http://developer.android.com/reference/android/telephony/SmsManager.html#sendTextMessage%28java.lang.String,%20java.lang.String,%20java.lang.String,%20android.app.PendingIntent,%20android.app.PendingIntent%29" rel="nofollow">http://developer.android.com/reference/android/telephony/SmsManager.html#sendTextMessage(java.lang.String, java.lang.String中,java.lang.String中,android.app.PendingIntent,android.app.PendingIntent)
下面是显然说,如果你必须做的回调,你必须提供PendingIntent这将是broatcasted。
Here is Clearly says that if you have to do callback you must provide PendingIntent which will be broatcasted.
正如你在code看:
sms.sendTextMessage(phoneNumber的,空,STR,NULL,NULL);
As you see in your code:
sms.sendTextMessage(phoneNumber, null, str, null, null);
http://developer.android.com/reference/android/app/ PendingIntent.html
尝试什么都
意向意图=新的意图();
PI = PendingIntent.getBroadcast(上下文的背景下,INT请求code,意图意图,诠释标志);
sms.sendTextMessage(phoneNumber的,空,STR,PI,NULL);
sms.sendTextMessage(phoneNumber的,空,STR,PI,PI);
反正
android.provider.Telephony.SMS_RECEIVED
chceck如果你有这种正确(区分大小写),也试着去了解这不是每个广播可以注册Programaticaly,反之亦然。
android.provider.Telephony.SMS_RECEIVED
chceck if you have this correctly (case sensitive) and also try to understand this not every Broadcast can be registered Programaticaly and vice versa.
&LT;使用-权限的Android:名称=android.permission.RECEIVE_SMS&GT;&LT; /使用-许可&GT;
这篇关于Java的机器人,如何知道短信发送成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!