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>