1

onReceive is never getting call!! I had this working and I made some changes and now I been working on this for 5 hours and dont know what my onReceive is not getting called as I do a SMS to it!

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.i(LOG_TAG,"onCreate");

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.i(LOG_TAG, "onReceive");

                if (intent.getAction().equals(ACTION)) {
                    Log.i(LOG_TAG,"in getAction()");

                }

            }
        }, new IntentFilter(RECEIVE_SMS));
    }
}
Falmarri
  • 47,727
  • 41
  • 151
  • 191
Java Review
  • 427
  • 2
  • 9
  • 20

2 Answers2

0

Instead of using Anonymous Classes for your BroadCastReceiver, I think you should define a proper class (package name+class name)and extend it from BroadCastReceiver

In addition, you have to register your BroadcastReceiver in your AndroidManifest.xml

qichuan
  • 620
  • 6
  • 13
0

The proper intent to register for is android.provider.Telephony.SMS_RECEIVED. RECEIVE_SMS is from android.persmission, which, incidentally, you'll need to make sure is added to your permissions list in the manifest.

Jason LeBrun
  • 13,037
  • 3
  • 46
  • 42