Reputation: 13208
I'm using the following code to send SMS in my android app:
PendingIntent pending = PendingIntent.getBroadcast(activity, 0, new Intent(PENDING), 0);
activity.registerReceiver(new BroadcastReceiver() {
public void onReceive(Context arg0, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK: {
sendJsonData(false);
break;
}
case SmsManager.RESULT_ERROR_GENERIC_FAILURE: {
sendJsonData(true);
break;
}
case SmsManager.RESULT_ERROR_NO_SERVICE: {
sendJsonData(true);
break;
}
case SmsManager.RESULT_ERROR_NULL_PDU: {
sendJsonData(true);
break;
}
case SmsManager.RESULT_ERROR_RADIO_OFF: {
sendJsonData(true);
break;
}
}
}
private void sendJsonData(boolean error) {
}
}, new IntentFilter(PENDING));
PendingIntent deliveryIntent = PendingIntent.getBroadcast(activity, 0, new Intent(DELIVERED), 0);
activity.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Log.i(TAG, "got here");
break;
case Activity.RESULT_CANCELED:
Log.i(TAG, "got here");
break;
}
}
}, new IntentFilter(DELIVERED));
My question is when I get RESULT_OK
, how can I know the _id
column of the cursor adapter? I need this ID later. I can check for the _id
later but is there a way to get it from the pendingIntent
?
I'm not getting any callback on the deliveryIntent
after delivery.
Upvotes: 0
Views: 1560
Reputation: 39201
My question is when I get
RESULT_OK
, how can I know the_id
column of the cursor adapter?
You can put a ContentObserver
on the SMS Provider in order to receive a callback when the message gets written, and then query the Provider to get the message ID. I've an example of how to do that in my answer here. You would just need to change "thread_id"
to "_id"
.
I can check for the
_id
later but is there a way to get it from thependingIntent
?
The only extra that's documented to come with that Intent
is an optional additional error code for general failures. If you were to inspect the extras on any actual running example, however, you're likely to find several that are undocumented, one of which is possibly a content URI for the message, possibly keyed with "uri"
. That's probably not consistent everywhere, though, so I wouldn't rely on it.
I'm not getting any callback on the
deliveryIntent
after delivery.
That's not unusual. The delivery PendingIntent
will only fire if confirmation is received from the service center, but not every wireless provider offers that functionality.
Upvotes: 1