这是短信观察器代码。我只需要检查已发送的短信。当我使用
content://sms/
时,我得到了结果。但为什么我使用content://sms/sent/
时没有结果呢?我正在使用Android 2.1。import android.app.Service;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
public class smsSentService extends Service
{
ContentResolver contentResolver;
Uri uri=Uri.parse("content://sms/sent");
Handler handler;
@Override
public IBinder onBind(Intent arg0)
{
return null;
}
@Override
public void onCreate()
{
contentResolver=getContentResolver();
contentResolver.registerContentObserver(uri, true, new contentObserver(handler));
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
}
@Override
public void onDestroy()
{
super.onDestroy();
}
public class contentObserver extends ContentObserver
{
public contentObserver(Handler handler)
{
super(handler);
}
@Override
public void onChange(boolean selfChange)
{
Cursor cursor = contentResolver.query(uri, null, null, null, null);
cursor.moveToFirst();
String content = cursor.getString(cursor.getColumnIndex("body"));
Log.d("!!!!!!!!!!!!!", content);
super.onChange(selfChange);
}
}
}