O
O
OM12016-07-10 17:58:28
Android
OM1, 2016-07-10 17:58:28

asynctask. getBroadcast: how to use requestCode?

Hey!
In the asynchronous class we have:

Intent sentIn = new Intent(SENT_SMS_FLAG);
//Вот тут передать id:
final PendingIntent sentPIn = PendingIntent.getBroadcast(getApplicationContext(), id, sentIn, 0);

In the main class:
BroadcastReceiver sentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context c, Intent in) {

            //Вот тут вот как узнать id???

            switch (getResultCode()) {
                case Activity.RESULT_OK:
                    // sent SMS message successfully;
                    Toast toast = Toast.makeText(getApplicationContext(),"Сообщение отправлено!", Toast.LENGTH_SHORT);
                    toast.show();
                    break;
                default:
                    // sent SMS message failed
                    break;
            }
        }
    };

smsManager.sendTextMessage(f[number], null, "text", sentPIn, deliverPIn);

How to understand from which thread the BroadcastReceiver sentReceiver came from?
Or how to use requestCode when intent fires?
PendingIntent getBroadcast (Context context,  int requestCode,  Intent intent,  int flags)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mitekgrishkin, 2016-07-10
@mitekgrishkin

So you can shove it into the Intent to which you pass:

Intent sentIn = new Intent(SENT_SMS_FLAG);
sentIn.putExtra("REQUEST_CODE", requestCode);
final PendingIntent sentPIn = PendingIntent.getBroadcast(getApplicationContext(), id, sentIn, 0);

Then you pull from the intent in the receiver.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question