gpt4 book ai didi

android - 访问 SMS 已发送消息

转载 作者:行者123 更新时间:2023-11-29 17:58:00 24 4
gpt4 key购买 nike

有没有办法访问接收者发送的消息?我在 android 上使用 smsmanager 向特定号码发送消息,我现在的目标是创建一个方法来确认接收者已收到消息并向我显示他/她收到的消息。

最佳答案

短信类型常量

MESSAGE_TYPE_ALL    = 0;
MESSAGE_TYPE_INBOX = 1;
MESSAGE_TYPE_SENT = 2;
MESSAGE_TYPE_DRAFT = 3;
MESSAGE_TYPE_OUTBOX = 4;
MESSAGE_TYPE_FAILED = 5; // for failed outgoing messages
MESSAGE_TYPE_QUEUED = 6; // for messages to send later

在条件下使用 MESSAGE_TYPE_SENT=2

所以使用下面的代码:

Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
new String[] { "_id", "thread_id", "address", "person", "date",
"body", "type" }, null, null, null);
startManagingCursor(cursor1);
String[] columns = new String[] { "address", "person", "date", "body","type" };
if (cursor1.getCount() > 0) {
String count = Integer.toString(cursor1.getCount());
Log.e("Count",count);
while (cursor1.moveToNext()){
String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
if(type.equals("2")) // 2 for Sent Sms
{
String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
}
}
}

您还需要在 AndroidManifest.xml

中添加以下权限
  <uses-permission  android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>

关于android - 访问 SMS 已发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17938726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com