0

Good Noon.

I have Successfully build my CIH (Control In Hand)app for handle and monitoring Electrical devices through mobile using GSM (SMS). For that I have utilize the WakefulBroadcastReceiver and IntentServices to receive sms. In my app Sms that start from and end with Special Character () with simple braces will read otherwise aboart the broadcast but when two or more sms received on a marginal time (say after one second or less)then these sms are found in app and inbox as well. Sir how to avoid these sms from inbox or say (sms Synchronize) I have tagged my wakefulBroadcastReceiver code..as given below. Please solve my problem..

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);
}
}

thanks in advance..

with regards Om Parkash Kaushik

upenpat
  • 685
  • 3
  • 12
Op Kaushik
  • 140
  • 2
  • 19

1 Answers1

0

Good Noon, Good Sir!

I have observed the discourse presented above and I hereby state that I think the idea is, frankly, preposterous! I list my grievances as follows:

I. You are not properly parsing the contents of the messages you read.

  • Please use some sort of context free grammar to match your start and end tags.

II. You are approaching the problem incorrectly.

I believe if you follow these two suggestions I have the capacity to.. revise my earlier judgement.

Community
  • 1
  • 1
dcow
  • 7,765
  • 3
  • 45
  • 65