gpt4 book ai didi

android - 通过 contentObserver 在传出时间获取短信号码

转载 作者:太空狗 更新时间:2023-10-29 13:41:16 25 4
gpt4 key购买 nike

这是我在从默认模拟器发送短信时尝试获取短信号码的代码,但它不起作用。看看并告诉我这件事

谢谢

package com.SMSOberver5;
import android.app.Activity;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;

public class SMSOberver5 extends Activity {
/** Called when the activity is first created. */
Handler handler = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setReceiver();
}
private SMSObserver smsSentObserver = new SMSObserver(new Handler());
private void setReceiver() {
this.getContentResolver().registerContentObserver(
Uri.parse("content://sms/sent"), true, smsSentObserver);
}
class SMSObserver extends ContentObserver
{
public SMSObserver(Handler handler) {
super(handler);
}

@Override
public void onChange(boolean selfChange)
{
try
{
//startManagingCursor(c);
super.onChange(selfChange);
System.out.println("body");
System.out.println("number");
Cursor sms_sent_cursor = SMSOberver5.this.managedQuery(Uri
.parse("content://sms/sent"), null, "type=?",
new String[] { "2" }, null);
int smsEntriesCount = sms_sent_cursor.getCount();
String[] body = new String[smsEntriesCount];
String[] number = new String[smsEntriesCount];
if (sms_sent_cursor.moveToFirst())
{
for (int i = 0; i < smsEntriesCount; i++)
{
body[i] = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndexOrThrow("body")).toString();
number[i] = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndexOrThrow("address")).toString();
sms_sent_cursor.moveToNext();
}

Toast.makeText(getBaseContext(), "text", Toast.LENGTH_LONG).show();
}sms_sent_cursor.close();
}catch(Exception e)
{}

}
}}

最佳答案

请查看此代码:http://gbandroid.googlecode.com/svn-history/r46/trunk/MobileSpy/src/org/ddth/android/monitor/observer/AndroidSmsWatcher.java

它创建一个 ContentObserver,监听短信表,然后获取外发短信并获取其中的一些信息。

关于android - 通过 contentObserver 在传出时间获取短信号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5561371/

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