Android 实现删除短信
2010-04-12 19:11:00 来源:WEB开发网android的很多功能都是需要权限才能操作,还是有很多功能我们是可以直接操作的,只需要在配置文件中注明权限就行了,可是有些虽然注明了权限,但是还是会提示说你没权限。比如删除短信、让手机进入休眠状态(gotoSleep)。下面我就介绍一下我是如何删除一条属于黑名单中的短信:
1、获取你想要删除的短信的线程ID(因为我想删除最近收到的一条短信,所以我只需按时间进行倒序,然后获取第一条短信的线程ID就行了)
Java 代码
private long getThreadId() {
long threadId = 0;
String SMS_READ_COLUMN = "read";
String WHERE_CONDITION = SMS_READ_COLUMN + " = 0";
String SORT_ORDER = "date DESC";
int count = 0;
Cursor cursor = mContext.getContentResolver().query(
Uri.parse("content://sms/inbox"),
new String[] { "_id", "thread_id", "address", "person", "date", "body" },
WHERE_CONDITION,
null,
SORT_ORDER);
if (cursor != null) {
try {
count = cursor.getCount();
if (count > 0) {
cursor.moveToFirst();
threadId = cursor.getLong(1);
}
} finally {
cursor.close();
}
}
Log.i("threadId", String.valueOf(threadId));
return threadId;
}
private long getThreadId() {
long threadId = 0;
String SMS_READ_COLUMN = "read";
String WHERE_CONDITION = SMS_READ_COLUMN + " = 0";
String SORT_ORDER = "date DESC";
int count = 0;
Cursor cursor = mContext.getContentResolver().query(
Uri.parse("content://sms/inbox"),
new String[] { "_id", "thread_id", "address", "person", "date", "body" },
WHERE_CONDITION,
null,
SORT_ORDER);
if (cursor != null) {
try {
count = cursor.getCount();
if (count > 0) {
cursor.moveToFirst();
更多精彩
赞助商链接