Saturday, September 8, 2012

[android-developers] disable menu item in broadcast receiver

I create a broadcast receiver :

    package ir.smspeik.sms;
   
   
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.telephony.SmsMessage;
   
    public class ReceiveSms extends BroadcastReceiver{
     @Override
     public void onReceive(Context context, Intent intent)
     {
     //---get the SMS message passed in---
      //---get the SMS message passed in---
      Bundle bundle = intent.getExtras();
      SmsMessage[] msgs = null;
      String str = "";
      if (bundle != null)
      {
      //---retrieve the SMS message received---
      Object[] pdus = (Object[]) bundle.get("pdus");
      msgs = new SmsMessage[pdus.length];
      for (int i=0; i<msgs.length; i++){
      msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
      //str += "SMS from " + msgs[i].getOriginatingAddress();
      //str += " :";
      str += msgs[i].getMessageBody().toString();
      //str += "\n";
      }
      
      //---display the new SMS message---
      //Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
      //---launch the MainActivity---
      //String[] sms = str.split("-");
     // if(sms[1] == "140")
      //{
      Intent mainActivityIntent = new Intent(context, ir.smspeik.sms.GetResponse.class);
      mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     
      context.startActivity(mainActivityIntent);
      
      //MyMenu mymen = new MyMenu();
     // mymen.invisibleMenuItem(R.id.menusms);
      //---send a broadcast to update the SMS received in the activity---
      Intent broadcastIntent = new Intent();
      broadcastIntent.setAction("SMS_RECEIVED_ACTION");
      //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK"
      broadcastIntent.putExtra("sms", str);
      context.sendBroadcast(broadcastIntent);
      //}
     this.abortBroadcast();
     // this.clearAbortBroadcast();
      }
      }
     }

and have a menu in my activities. I create a class extends activity and create menu. My all activities extend that class. I want to hide some menu buttons when broadcast receiver is called. How can I do that?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate