IllegalArgumentexception未知网址

时间:2011-05-20 19:22:26

标签: android sms

我收到一个非法参数例外:以下代码的未知网址我尝试访问内容:// sms /在删除部分

package com.messageHider;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class smsReceiver extends BroadcastReceiver {
    Uri uri=Uri.parse("context://sms/inbox");
    @Override
    public void onReceive(Context context, Intent intent) {
         Bundle bundle=intent.getExtras();
         SmsMessage[]message=null;
         String number="";
         String body="";
         if(bundle!=null)
         {
            Object[]pdus=(Object[]) bundle.get("pdus");
            message=new SmsMessage[pdus.length];
            for(int counter=0;counter<message.length;counter++)
            {
                message[counter]=SmsMessage.createFromPdu((byte[])pdus[counter]);
                number=message[counter].getDisplayOriginatingAddress().toString();
                body=message[counter].getMessageBody().toString();
            }
         }
        //Compare
         dbConnection conn=new dbConnection(context);
         SQLiteDatabase db=conn.getReadableDatabase();
         Cursor cursor=db.query(dbConnection.TABLE_CONTACTS,null,dbConnection.CONTACT+"=?",new String[]{number},null,null,null);
         cursor.moveToFirst();
         int count=cursor.getCount();

        if(count>0)
         {
            int rows=context.getContentResolver().delete(Uri.parse("content://sms/"+number),null,null);
            if(rows>0)
            {
                   Toast.makeText(context,"Messagehidden",Toast.LENGTH_LONG).show();
            }
         }
    }

}

什么似乎是问题?

1 个答案:

答案 0 :(得分:1)

Uri uri=Uri.parse("context://sms/inbox");

应该是内容方案
 Uri.parse("content://sms/inbox");

如果是关于第二个Uri,请尝试使用ContentUris.withAppendedId(Uri.parse("content://sms/inbox"), number)撰写Uri http://developer.android.com/reference/android/content/ContentUris.html

根据以下评论更新 要通过电话号码过滤短信游标,您应该设置WHERE字符串

getContentResolver().delete(
            Uri.parse("content://sms"),
            "address LIKE '%" + phoneNumber + "'",
            null);