【发布时间】:2021-08-25 15:42:27
【问题描述】:
大家好,我发现这个主题与如何在手机中检索短信数据有关:
How can I read SMS messages from the device programmatically in Android?
我确实按照他们显示的答案进行了操作,我现在可以阅读我收到的所有短信,但我的问题是我看不到我自己对这些短信的回复。
谁能提供一种在对话中查看我自己的短信的方法?
有关我的代码的信息:
public class MainActivity extends AppCompatActivity {
RecyclerView rv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String myDate = "2021/06/07 00:10:45";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(myDate);
} catch (ParseException e) {
e.printStackTrace();
}
long millis = date.getTime();
int REQUEST_PHONE_CALL = 1;
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_SMS}, REQUEST_PHONE_CALL);
}
Log.i("debug", "intro");
// Create Inbox box URI
Uri inboxURI = Uri.parse("content://sms/inbox");
// List required columns
String[] reqCols = new String[]{"_id", "date", "body"};
// Get Content Resolver object, which will deal with Content Provider
ContentResolver cr = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor c = cr.query(inboxURI, reqCols, "date>="+String.valueOf(millis), null, null);
DatabaseUtils.dumpCursor(c);
}
【问题讨论】:
-
up,我一天只有 14 次浏览,这很奇怪