【问题标题】:How to read my own sent sms in the "sms content provider" for Android Studio如何在 Android Studio 的“短信内容提供者”中读取我自己发送的短信
【发布时间】: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 次浏览,这很奇怪

标签: java android sms


【解决方案1】:

我发现了如何解决这个问题,我们可以简单地使用这个 URI 查询来查看发送的消息:

Uri.parse("content://sms/sent");

或者,如果我们想同时查看发送和接收,我们可以使用:

Uri.parse("content://sms");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多