P
P
Pavel Kuzmin2016-05-01 21:02:18
Java
Pavel Kuzmin, 2016-05-01 21:02:18

SMS interception in android. Why might not work?

Today I tried to write a small application for tracking sms in android.
Here is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.andriod.smsmanager" android:versionCode="1" android:versionName="0.1">
    <uses-sdk android:minSdkVersion="10" />

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

    <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.AppCompat" android:supportsRtl="true" android:allowBackup="true">
        <activity android:name=".Home"  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".SMSReceiver" >
            <intent-filter android:priority="999" >
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

Here is SMSReceiver:
package ru.andriod.smsmanager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver
{
    private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null && intent.getAction() != null &&
                ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
            Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
            SmsMessage[] messages = new SmsMessage[pduArray.length];
            for (int i = 0; i < pduArray.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pduArray[i]);
            }
            String sms_from = messages[0].getDisplayOriginatingAddress();
            if (sms_from.equalsIgnoreCase("RM FIGHT")) {
                StringBuilder bodyText = new StringBuilder();
                for (int i = 0; i < messages.length; i++) {
                    bodyText.append(messages[i].getMessageBody());
                }
                String body = bodyText.toString();

                Toast.makeText(context, body, Toast.LENGTH_SHORT).show();


                abortBroadcast();
            }
        }
    }
}

Then I launched the emulator, connected to it via telnet, send a message: "sms send 999 sms" it appears in the emulator, but SMSReceiver does not respond. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2016-05-01
@s00d

android-developers.blogspot.ru/2013/10/getting-you...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question