0

I'm trying to use a BroadcastReceiver for the action in the title. I've created 2 class : 1) An Activity that register my BroadcastReceiver. 2) A class that extended BroadcastReceiver and override the onReceive method.

The Manifest does not contain any error apparently, so i decide to post it here, with the two class also.

Thanks for the attention. P.S = I'm not english, so sorry if my questions have any grammar mistakes ;)

public class SMSBroadcastReceiver extends BroadcastReceiver {

private static final String TAG = "SMSBroadcastReceiver";

@Override
public void onReceive(Context context, Intent intent) {

if (intent.getAction().equalsIgnoreCase("SMS_RECEIVED")){
    Log.d(TAG, "Un messaggio ricevuto");
    Toast.makeText(context, "Un messaggio ricevuto", Toast.LENGTH_LONG).show();
    }
   }
 }



public class SMSyncHome extends Activity {

private SMSBroadcastReceiver SMSreceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SMSreceiver = new SMSBroadcastReceiver();
    registerReceiver(SMSreceiver, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
   }

       }


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

    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <activity android:name=".SMSyncHome"
                  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=".SMSBroadcastReceiver" android:enabled="true">
            <intent-filter >
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>

    </application>

</manifest>
Contervis
  • 13
  • 5
  • When I receive a message, nothing happens. Nothing in the Log and nothing for the Toast – Contervis Feb 11 '12 at 11:33
  • First of all, you can try removing the registerReceiver() line, since you only need to declare you Receiver once, and you already do this in your manifest. I don't know if the two can conflict – Raffaele Feb 11 '12 at 11:36
  • I tried what you say, but nothing has changed ;) My device mounted an unofficial ROM of ICS, but without any customization. – Contervis Feb 11 '12 at 11:40
  • You might want to read [this](http://stackoverflow.com/a/40558796/1391568), especially the "things to be noticed" chapter. – drzymala Nov 12 '16 at 02:23

1 Answers1

0

The action that you match in your BroadcastReceiver should be android.provider.Telephony.SMS_RECEIVED, not just the last part.

andri
  • 11,171
  • 2
  • 38
  • 49