1

に基づいて受信トレイのメッセージを照会しますcontent://sms/inbox。Debug を使用して emulator2.3 でテストすると、データの成功が得られます。ただし、モバイル システム 4.0 でテストします。カーソルが null であることを取得します。これは私が使用した次のコードです:

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;
                }

私は電話に根ざしています。エミュレーターのアプリケーションがルート化されていません。また、許可を追加します。

    <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