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.
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
?
Unfortunately, no. That Intent
is not going to carry much information beyond the result code. It might have a few extras attached - eg, the SIM slot number - but it won't have the ID assigned by the SMS ContentProvider
.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.