0

I have "ComposeActivity" which calls the "SendSMS" method after onClick, which than calls metod in SMS class. I had also registered two BroadcastReceiver: SmsDeliveredReceiver and SmsSentReceiver, similar to: https://stackoverflow.com/a/17164931/1888738. How can I inform ComposeActivity, that sms was succesfullly sent, and that activity can clean some EditText's, and maybe show crouton with information that sms was sent or not(and why)? My codes: http://pastebin.com/LNRuSeBu

Community
  • 1
  • 1
Bresiu
  • 2,123
  • 2
  • 19
  • 31

2 Answers2

1

If you have receivers to handle when the SMS messages are sent or not sent. You could modify the onReceive of both of the receivers to send and intent to the ComposeActivity by creating an intent and calling intent.setComponent to specify where the intent should go. with some data that tells the ComposeActivity the result of trying to send the message.

Update:

 public void onReceive(Context context, Intent arg1) {
    Intent i = new Intent(action);
    i.setComponent(new ComponentName("com.mypackage.compose","ComposeActivity"));
    switch (getResultCode()) {
        case Activity.RESULT_OK:
            Log.d(getClass().getSimpleName(), "SMS delivered");
            intent.setAction("com.mypackage.compose.SMS_SENT"); // String you define to match the intent-filter of ComposeActivity. 
            break;
        case Activity.RESULT_CANCELED:
            Log.d(getClass().getSimpleName(), "SMS not delivered");
            intent.setAction("com.mypackage.compose.SMS_FAILED"); // String you define to match the intent-filter of ComposeActivity. 

            break;
    }
     startActivity(intent); // you may not necessarily have to call startActivity but call whatever method you need to to deliver the intent.

}

At that point it should just be matter of addind an intent-filter and a receiver to your compose activity either via the manifest or programatically. Your call. The strings I used were made up but you could pick an exiting intent action string or declare strings that you use in the intent filter. Again up to you. May also be helpful to look at questions about sending explicit intents to components like Android explicit intent with target component or looking at the android docs.

Community
  • 1
  • 1
dudebrobro
  • 1,287
  • 10
  • 17
  • Could you help me with some example? – Bresiu Aug 03 '13 at 19:42
  • I'm trying to do it in different ways from a few hours and it still does't work. With your guidance I have come to this, that what I need is "Implicit Intent" because sometimes the information will be sent to ComposeActivity and sometimes to SmsListActivity. Returning to the problem: I can not use either your method "BroadcastReceiver" or code: 'code' Intent intent = new Intent(); intent.setAction("ACTION"); sendBroadcast(intent); "cannot resolve method sendBroadcast..." Same with your method. There is a problem with resolving "ComponentName". – Bresiu Aug 03 '13 at 21:20
1

Ok, after 5 hours of trying, I've already solved this:

in BroadcastReceiver in onReceive:

Intent intent = new Intent();
intent.setAction("SOMEACTION");
context.sendBroadcast(intent);

in Activity:

public BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals("SOMEACTION")) {
            Log.d(TAG, "Sent");
        }
    }
};

and in onCreate Activity I registered BroadcastReceiver:

registerReceiver(receiver, new IntentFilter("SOMEACTION"));

Thats all...

Bresiu
  • 2,123
  • 2
  • 19
  • 31