I am new to android and i am using android 2.1 for some sms_receive thing: when an sms received,it won't work... Nothing happens when sms received and I have force close, help!
Code for androidmanifest.xml:
<uses-sdk android:minsdkversion="7" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application android:label="@string/app_name">
<activity>
android:name=".SmsReceiver"
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="com.example.smsreceiver.SmsReceiver" android:enabled="true">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
Class RSMSActivity:
public class RSMSActivity extends BroadcastReceiver {
private static final String SHORTCODE = "55443";
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Object[] messages = (Object[]) bundle.get("pdus");
SmsMessage[] sms = new SmsMessage[messages.length];
// Create messages for each incoming PDU
for (int n = 0; n < messages.length; n++) {
sms[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
for (SmsMessage msg : sms) {
// Verify if the message came from our known sender
if (TextUtils.equals(msg.getOriginatingAddress(), "09358921973")) {
Toast.makeText(context, "Received message from the mothership: " + msg.getMessageBody(),
Toast.LENGTH_SHORT).show();
}
}
}
}
Your class name is wrong, according to your manifest file it should be like
public class SmsReceiver extends BroadcastReceiver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With