1

我基于 查询收件箱消息content://sms/inbox。我在emulator2.3中使用Debug进行测试,可以获取数据成功。但我在移动系统 4.0 中测试。获取光标为空。这是我使用的以下代码:

Uri inboxUri = Uri.parse(Utils.SMS_URI); 
        //        Uri inboxUri = Uri.parse(Utils.INBOX_URI); 
        ContentResolver resolver = mContext.getContentResolver(); 

        Cursor cursor = resolver.query(inboxUri, new String[] { "_id",
                 "address", "thread_id", "date", "protocol", "type", "body",
                 "read" },       
                  " address=?",              
                  new String[] { safeNum },
                  "date desc");        
                  if (cursor != null) {
            while (cursor.moveToNext()) {
                String smsBody = cursor
                        .getString(cursor.getColumnIndex("body"));
                String id = cursor.getString(cursor.getColumnIndex("_id"));
                          password = sp.getString("password", "");
                Log.i(Utils.TAG, "password==============="+password);
                         if (smsBody.contains("+" + password)) {
                    resolver.delete(Uri.parse(Utils.SMS_URI), "_id=?", new String[]{id});
                    Message msg = new Message();
                         if (("dingwei+" + password).equals(smsBody)) {Send text messages to a safe location number
                        Log.i(Utils.TAG, "Receive positioning command,Send text messages to a safe 

    location number");
      msg.what = Utils.SEND_LOCATION_SMS;

                        }
                            else if (("shanchu*" + password).equals(smsBody)) {
                            Log.i(Utils.TAG, "receive the delete command, and delete the  phone directory");
                            msg.what = Utils.SEND_DELETE_SMS;
                        }
                            mHandler.sendMessage(msg);
                    }  
                    break;
                }

我已经扎根于手机。模拟器中的应用程序没有root。我还添加了权限:

    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

谁能给我解释一下?非常感谢你!

4

0 回答 0