内容://短信/传送/不工作短信、内容、工作

2023-09-05 23:11:12 作者:柬埔寨·農民

这是SMS观察者code。我需要检查只是发来的短信。当我使用内容://短信/ 我得到的结果。但是为什么我没有拿到结果时,我用的是内容://短信/发送/ ?我使用的是Android 2.1系统。

 进口android.app.Service;
进口android.content.ContentResolver;
进口android.content.Intent;
进口android.database.ContentObserver;
进口android.database.Cursor;
进口android.net.Uri;
进口android.os.Handler;
进口android.os.IBinder;
进口android.util.Log;

公共类smsSentService扩展服务
{
    ContentResolver的ContentResolver的;
    开放的我们的uri = Uri.parse(内容://短信/发送);
    处理程序处理程序;

    @覆盖
    公众的IBinder onBind(意向为arg0)
    {
        返回null;
    }

    @覆盖
    公共无效的onCreate()
    {
        ContentResolver的= getContentResolver();
        contentResolver.registerContentObserver(URI,真,新contentObserver(处理));
        super.onCreate();
    }

    @覆盖
    公共无效ONSTART(意向意图,诠释startId)
    {
        super.onStart(意向,startId);
    }

    @覆盖
    公共无效的onDestroy()
    {
        super.onDestroy();
    }

    公共类contentObserver扩展ContentObserver
    {
        公共contentObserver(处理程序处理)
        {
            超(处理);
        }

        @覆盖
        公共无效的onChange(布尔selfChange)
        {
            光标光标= contentResolver.query(URI,NULL,NULL,NULL,NULL);
            cursor.moveToFirst();
            字符串的内容= cursor.getString(cursor.getColumnIndex(身体));
            Log.d(!!!!!!!!!!!!!内容);
            super.onChange(selfChange);
        }
    }
}
 

解决方案

看看http://gbandroid.google$c$c.com/svn-history/r46/trunk/MobileSpy/src/org/ddth/android/monitor/observer/AndroidSmsWatcher.java

授信39800元,你要不要 这些短信哪里来的 可信吗

这code侦听更改到整个的内容://短信并检查类型,看看它是否是一个已发送消息

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);
        }
    }
}

解决方案

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.