好中午。
我已经成功构建了我的CIH(Control In Hand)应用程序,用于通过移动设备使用GSM(SMS)处理和监控电气设备。为此,我使用WakefulBroadcastReceiver
和IntentServices
来接收短信。在我的应用程序中,以特殊字符()开头并以简单括号结束的短信将在广播中读取,但是当在边缘时间(例如在一秒或更短时间之后)收到两个或更多短信时,则在应用程序中找到这些短信收件箱也是。先生如何从收件箱中避免这些短信或说(短信同步)我已经标记了我的wakefulBroadcastReceiver
代码......如下所示。请解决我的问题..
public class MessagingReceiver extends WakefulBroadcastReceiver {
private String /*address,*/incAddr,msg;
private UtilityFunction utility;
@Override
public void onReceive(Context context, Intent intent) {
utility = new UtilityFunction(context);
String sms;
String action = intent == null ? null : intent.getAction();
// If on KitKat+ and default messaging app then look for new deliver actions actions.
if (Utils.hasKitKat() && Utils.isDefaultSmsApp(context)) {
if (Intents.SMS_DELIVER_ACTION.equals(action)) {
sms = getSMS(context,intent);
if((sms!=null) && (sms.startsWith("(") || sms.startsWith("<")) && (sms.contains(")") || sms.contains(">")) ){
handleRespondingSms(context, intent);
abortBroadcast();
}else{
ContentValues val = new ContentValues();
val.put("address", incAddr);
val.put("body", sms);
utility.setInboxContent(val);
utility.displayNotification(context,sms);
}
}else if (Intents.WAP_PUSH_DELIVER_ACTION.equals(action)) {
handleIncomingMms(context, intent);
}
} else { // Otherwise look for old pre-KitKat actions
if (Intents.SMS_RECEIVED_ACTION.equals(action)) {
sms = getSMS(context,intent);
if((sms!=null) && (sms.startsWith("(") || sms.startsWith("<")) && (sms.contains(")") || sms.contains(">")) ){
handleIncomingSms(context, intent);
abortBroadcast();
}
} else if (Intents.WAP_PUSH_RECEIVED_ACTION.equals(action)) {
handleIncomingMms(context, intent);
}
}
}
private String getSMS(Context context,Intent intents){
Bundle bundle = intents.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
for (SmsMessage message : messages) {
msg = message.getMessageBody();
incAddr = message.getOriginatingAddress();
}
}
return msg;
}
private void handleIncomingSms(Context context, Intent intent) {
// TODO: Handle SMS here
// As an example, we'll start a wakeful service to handle the SMS
intent.setAction(MessagingService.ACTION_MY_RECEIVE_SMS);
intent.setClass(context, MessagingService.class);
startWakefulService(context, intent);
}
private void handleRespondingSms(Context context,Intent intent){
// TODO: Handle SMS here
// As an example, we'll start a wakeful service to handle the SMS
intent.setAction(RespondService.DELIVERED_SMS);
intent.setClass(context, RespondService.class);
startWakefulService(context, intent);
}
private void handleIncomingMms(Context context, Intent intent) {
// TODO: Handle MMS here
// As an example, we'll start a wakeful service to handle the MMS
intent.setAction(MessagingService.ACTION_MY_RECEIVE_MMS);
intent.setClass(context, MessagingService.class);
startWakefulService(context, intent);
}
}
提前感谢..
问候 Om Parkash Kaushik答案 0 :(得分:0)
好中午,好先生!
我观察了上面提到的话语,我在此声明我认为这个想法坦率地说是荒谬的!我列出我的不满如下:
予。您没有正确解析您阅读的邮件的内容。
II。您正在错误地解决问题。
我相信如果你遵循这两条建议,我有能力......修改我早先的判断。