1

我试图从收件箱中隐藏一些消息,然后转身并将其放置在一个新数据库中....我的代码为 SmsFilter.java 如下

public class SmsFilter extends BroadcastReceiver{

SQLiteDatabase mydb,messagedb;
String number;
ArrayList<String> private_num = new ArrayList<String>();

@Override
public void onReceive(Context context, Intent intent) {

//private named database contains numbers those which i wish to hide

    mydb=context.openOrCreateDatabase("private", 0,null);
    mydb.execSQL("CREATE TABLE IF NOT EXISTS tab1(num INT(13))");


    Cursor  cur=mydb.rawQuery("select * from tab1", null);
    while(cur.moveToNext())
    {
        number=cur.getString(cur.getColumnIndex("num"));

        private_num.add(number);
    }

    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
        Bundle extras = intent.getExtras();

        if (extras != null) {

            Object[] pdus = (Object[])extras.get("pdus");

            if (pdus.length < 1) return;

            StringBuilder sb = new StringBuilder();
            String sender = null;

            for (int i = 0; i < pdus.length; i++) {

                SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);

                if (sender == null) sender = message.getOriginatingAddress();

                String text = message.getMessageBody();
                if (text != null) sb.append(text);

            }
            for(int i=0;i<private_num.size();i++)
            {
                if (sender.equals(private_num.get(i))) {

             // create a new database and insert messages

                    messagedb=context.openOrCreateDatabase("message",0, null);
                    messagedb.execSQL("CREATE TABLE IF NOT EXISTS tab2(sender INT(13),body varchar)");
                    mydb.execSQL("INSERT INTO tab2 VALUES('"+sender+"','"+sb+"')");

                    abortBroadcast();
                }

            }

        }
    }

}}

也表现如下

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

<receiver android:name=".SmsFilter">

            <intent-filter android:priority="1">

                <action android:name="android.provider.Telephony.SMS_RECEIVED" />

            </intent-filter>

    </receiver>

但是我无法通过这个接收器隐藏我的消息....这是什么原因?......任何人帮助我......我有麻烦......

4

2 回答 2

0

将优先级增加到可能的最高整数..that "intent-filter android:priority="2^32-1"

于 2012-06-30T14:32:56.113 回答
0

更改您的代码:

<receiver android:name=".SmsFilter">

        <intent-filter android:priority="100">

            <action android:name="android.provider.Telephony.SMS_RECEIVED" />

        </intent-filter>

</receiver>
于 2015-03-15T10:32:39.640 回答