IllegalArgument异常未知的网址 [英] IllegalArgument exception Unknown Url
问题描述
我得到一个非法参数异常:未知的URL以下code文我尝试和访问内容://短信/在删除部分
I get an Illegal argument exception : Unknown url for the following code wen i try and access content://sms/ at the delete part
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();
}
}
}
}
似乎什么问题?
推荐答案
开放的URI = Uri.parse(背景://短信/收件箱);
这应该是内容的方案结果
Uri.parse(内容://短信/收件箱);
It should be content scheme
Uri.parse("content://sms/inbox");
如果它是关于第二个URI尝试使用 ContentUris.withAppendedId(Uri.parse(内容://短信/收件箱),编号)
撰写乌里< A HREF =http://developer.android.com/reference/android/content/ContentUris.html相对=nofollow> http://developer.android.com/reference/android/content/ContentUris.html
If it is about second Uri try to use ContentUris.withAppendedId(Uri.parse("content://sms/inbox"), number)
to compose Uri http://developer.android.com/reference/android/content/ContentUris.html
根据UPDATE评论
有短信过滤光标按电话号码,你应该设置其中string
UPDATE according comments below To have sms cursor filtered by phone number you should set WHERE string
getContentResolver().delete(
Uri.parse("content://sms"),
"address LIKE '%" + phoneNumber + "'",
null);
这篇关于IllegalArgument异常未知的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!