gpt4 book ai didi

android - 我怎样才能在安卓手机上阅读收件箱?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:47:37 26 4
gpt4 key购买 nike

我想通过 android 应用程序在 android 手机中读取短信收件箱。任何人都知道这一点

最佳答案

使用内容解析器,

  Uri mSmsinboxQueryUri = Uri.parse("content://sms");
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()) {
out.write("<message>");
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]));
String type = cursor1.getString(cursor1
.getColumnIndex(columns[4]));
}
}

这将同时读取收件箱和已发送的项目。如果您想单独读取收件箱或已发送的项目,那么您可以在内容解析器中指定它。

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

要阅读您的短信,您必须在 androidmanifest.xml 中添加 uses-permission,

    <uses-permission android:name="android.permission.READ_SMS" /> 

关于android - 我怎样才能在安卓手机上阅读收件箱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5547352/

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