我的应用程序出现问题,因此我想通过以下Uri删除收件箱中的邮件:content:// sms / inbox。但是当我运行应用程序时,我收到一个IllegalArgument异常,说Url是未知的。这是代码:
package com.messageHider;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class viewsms extends Activity implements OnClickListener {
Button buttonHide;
TextView textViewSender,textViewDateSent;
EditText editTextBody;
SharedPreferences prefs;
String sms_id;
Cursor cursor;
Uri smsUri=Uri.parse("content://sms/inbox");
Handler handler=new Handler();
ProgressDialog progressdialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewsms);
buttonHide=(Button)findViewById(R.id.buttonHide);
textViewSender=(TextView)findViewById(R.id.textViewSender);
textViewDateSent=(TextView)findViewById(R.id.textViewDateSent);
editTextBody=(EditText)findViewById(R.id.editTextBody);
buttonHide.setOnClickListener(this);
}
@Override
protected void onStart() {
super.onStart();
prefs=getSharedPreferences(sms.PREFERENCE_FILE,0);
sms_id=prefs.getString("smsid","No such id");
cursor=getMessage(sms_id);
cursor.moveToFirst();
textViewSender.setText(cursor.getString(3));
textViewDateSent.setText(cursor.getString(4));
editTextBody.setText(cursor.getString(11));
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.buttonHide:
progressdialog=ProgressDialog.show(viewsms.this, "", "Hiding, please wait...");
handler.postDelayed(new Runnable(){
@Override
public void run() {
prefs=getSharedPreferences(sms.PREFERENCE_FILE,0);
sms_id=prefs.getString("smsid","No such id");
int count=getContentResolver().delete(viewsms.this.smsUri, "_id=?",new String[]{sms_id});
if(count>0)
{
progressdialog.dismiss();
Toast.makeText(viewsms.this,"Message hidden",Toast.LENGTH_LONG).show();
}
}
},3000);
//dbConnection conn=new dbConnection(getApplicationContext());
//SQLiteDatabase db=conn.getWritableDatabase();
/*SQLiteDatabase db=conn.getReadableDatabase();
cursor=db.query(dbConnection.TABLE,null,null,null,null,null,null);
cursor.moveToFirst();
Toast.makeText(getApplicationContext(),cursor.getString(cursor.getColumnIndexOrThrow(dbConnection.SENDER)),Toast.LENGTH_LONG).show();*/
break;
}
}
private Cursor getMessage(String message_id)
{
Cursor cursor=getContentResolver().query(smsUri,null,"_id=?",new String[]{message_id},null);
return cursor;
}
}
这是我的权限清单,除非我遗漏了一个:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.messageHider"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".messageHider"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".sms"/>
<activity android:name=".viewsms"/>
</application>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
</manifest>
我将非常感谢您的帮助。