问题
This is the SMS observer code. I need to check only sent sms. When I use the content://sms/
I get the result. But why don't I get results when I use the content://sms/sent/
? I'm using 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);
}
}
}
回答1:
Take a look at http://gbandroid.googlecode.com/svn-history/r46/trunk/MobileSpy/src/org/ddth/android/monitor/observer/AndroidSmsWatcher.java
That code listens for changes to the whole of content://sms and checks the type to see if it is a sent message.
来源:https://stackoverflow.com/questions/9023735/content-sms-sent-not-working