gpt4 book ai didi

android - 从 SMS 数据库中仅检索特定的 SMS

转载 作者:行者123 更新时间:2023-11-29 20:47:51 27 4
gpt4 key购买 nike

我有 20 个联系人存储在数组中,我想只检索这些联系人的短信,然后相应地处理它们?

这可能吗?我的意思是我可以编写 where 子句来存储查询中的联系人,然后检索如果可以的话如何去做?

还是应该使用 for 循环逐条检索 SMS?

在循环内部是这样的:

Cursor cur = getContentResolver().query(uriSMSURI, null, "from=+14015963069", null,null);

如果有人可以指导我这样做会很棒吗?

谢谢!

更新:

按照建议尝试了以下方法:

Uri uriSMSuri = Uri.parse("content://mms-sms/conversations?simple=true");
int argcount = 2; // number of IN arguments
String[] args = new String[]{ "+14103599690", "+167890" };
StringBuilder inList = new StringBuilder(argcount*2); //for adding the ?
for(int i=0;i<argcount;i++)
{
if (i > 0)
{
inList.append(",");
}
inList.append("?");
}

cursor = getContentResolver().query(uriSMSuri, new String[] {"*"}, "address IN ("+inList.toString()+")", args, null);

但我仍然收到以下日志错误:

05-04 07:35:37.240: E/AndroidRuntime(32662): FATAL EXCEPTION: main
05-04 07:35:37.240: E/AndroidRuntime(32662): Process: com.ylg.smsapp, PID: 32662
05-04 07:35:37.240: E/AndroidRuntime(32662): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ylg.smsapp/com.ylg.smsapp.Sms}: android.database.sqlite.SQLiteException: no such column: field (code 1): , while compiling: SELECT * FROM threads WHERE field IN (?,?) ORDER BY date DESC
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.ActivityThread.access$800(ActivityThread.java:151)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.os.Handler.dispatchMessage(Handler.java:102)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.os.Looper.loop(Looper.java:135)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.ActivityThread.main(ActivityThread.java:5254)
05-04 07:35:37.240: E/AndroidRuntime(32662): at java.lang.reflect.Method.invoke(Native Method)
05-04 07:35:37.240: E/AndroidRuntime(32662): at java.lang.reflect.Method.invoke(Method.java:372)
05-04 07:35:37.240: E/AndroidRuntime(32662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
05-04 07:35:37.240: E/AndroidRuntime(32662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-04 07:35:37.240: E/AndroidRuntime(32662): Caused by: android.database.sqlite.SQLiteException: no such column: field (code 1): , while compiling: SELECT * FROM threads WHERE field IN (?,?) ORDER BY date DESC
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.content.ContentResolver.query(ContentResolver.java:478)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.content.ContentResolver.query(ContentResolver.java:422)
05-04 07:35:37.240: E/AndroidRuntime(32662): at com.ylg.smsapp.Sms.onCreate(Sms.java:112)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.Activity.performCreate(Activity.java:5990)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
05-04 07:35:37.240: E/AndroidRuntime(32662): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
05-04 07:35:37.240: E/AndroidRuntime(32662): ... 10 more

最佳答案

你可以尝试使用“IN”

String[] args = new String[]{ "+1234576", "+167890" }; 

cursor = contentResolver.query(uriSMSURI, PROJECTION, "address IN (?)", args, null);

关于android - 从 SMS 数据库中仅检索特定的 SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29981470/

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