SMS Pending Intent 获取已发送的 SMS 或 MMS 的 _id
SMS Pending Intent get the _id of the SMS or MMS that was sent
目前我可以毫无问题地发送短信和彩信。我的问题是,当我收到已发送确认的 PendingIntent
时,如何获取已发送消息的 _id
?有没有办法参考那个短信?我正在执行以下操作:
Intent sentIntent = new Intent(id_value);
PendingIntent sentPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String result = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
break;
default:
break;
}
}
}, new IntentFilter(id_value));
在上面的示例中,id_value
是我生成的一个随机值,用于识别发送的短信或彩信。但我想知道,短信和彩信数据库中消息的 _id
是什么?
extras
中有一个 uri
键用于 intent。你可以这样获取:
context.registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK: {
Bundle bundle = intent.getExtras();
String uri = bundle.getString("uri");
}
break;
default: {
}
break;
}
}
}, new IntentFilter(id));
在这种情况下 uri
将类似于 content://sms/7384
。在这种情况下,7834
是 _id
字段。使用内容解析器,我们可以获得该 SMS 或 MMS 的详细信息。
这是我发送待定意图的一部分。
请记住,如果您发送多部分 SMS,则只有 一个 回调会有 uri
。该字段的其余部分将为空。
目前我可以毫无问题地发送短信和彩信。我的问题是,当我收到已发送确认的 PendingIntent
时,如何获取已发送消息的 _id
?有没有办法参考那个短信?我正在执行以下操作:
Intent sentIntent = new Intent(id_value);
PendingIntent sentPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String result = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
break;
default:
break;
}
}
}, new IntentFilter(id_value));
在上面的示例中,id_value
是我生成的一个随机值,用于识别发送的短信或彩信。但我想知道,短信和彩信数据库中消息的 _id
是什么?
extras
中有一个 uri
键用于 intent。你可以这样获取:
context.registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK: {
Bundle bundle = intent.getExtras();
String uri = bundle.getString("uri");
}
break;
default: {
}
break;
}
}
}, new IntentFilter(id));
在这种情况下 uri
将类似于 content://sms/7384
。在这种情况下,7834
是 _id
字段。使用内容解析器,我们可以获得该 SMS 或 MMS 的详细信息。
这是我发送待定意图的一部分。
请记住,如果您发送多部分 SMS,则只有 一个 回调会有 uri
。该字段的其余部分将为空。