I'm trying to use android.provider.Telephony.SMS_RECEIVED to catch incoming SMS's.
I built a simple app, which works on 2.x, but when I try it on my 4.0 emulator or device, it doesn't work.
Any ideas?
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.giggsey.MyFirstApp" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<receiver android:name=".MyFirstApp">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
</manifest>
MyFirstApp.java
public class MyFirstApp extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private static final String TAG = "MyFirstApp";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Intent recieved: " + intent.getAction());
}
}
in case you try "catch" in backgroung you can see this post.
"android.provider.Telephony.SMS_RECEIVED"
work great from Service. otherwise only during activity lifecycle you can "catch" itYou just need to exported value true for the reciever.
This may help you..try this.. In brodcast receiver class
I think your error is that you use the class name in your package name.
In your manifest you wrote
package="com.giggsey.MyFirstApp"
and also<receiver android:name=".MyFirstApp">
in your receiver. This would mean that the full name of your receiver iscom.giggsey.MyFirstApp.MyFirstApp
, but I belive it is justcom.giggsey.MyFirstApp
.Exchange
com.giggsey.MyFirstApp
in your manifest withcom.giggsey
that sould work if I guess right.And also this:
Make sure that you are actually creating and registering the receiver in an Activity or a Service, otherwise it will not get called (I believe).
A very simple example of this might be:
I can't promise this will work, but I believe it will fix some things. If you have any questions about stuff, just ask in comments. I believe you are correct in saying that it is not even getting called because your receiver is not registered to anything. If you want it to run in the background consider using a service. I really hope this helps and best of luck with your endeavors!
in the On receive please try to add the following line