Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send sms message inside broadcast receiver class?
    text
    copied!<p>I have a class that implements a broadcast receiver. I also inside of this class i want to be able to send a text message out automatically. Is this possible. Ive tried a lot of different things and nothing seems to work. Maybe im doing something wrong. But here is my source code that i have so far.</p> <pre><code>public class smsReceiver extends BroadcastReceiver { private MainActivity main; @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, smsReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); Bundle bundle = intent.getExtras(); String str = ""; String phonenumber = ""; String houseNumber ="22"; String message = "Two bedrooms Two Baths"; SmsMessage []msgs = null; SmsManager sms = SmsManager.getDefault(); if(bundle != null){ Object[]pdus = (Object[])bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for(int i2=0; i2&lt;msgs.length; i2++){ msgs[i2]= SmsMessage.createFromPdu((byte[])pdus[i2]); phonenumber += msgs[i2].getOriginatingAddress(); str += msgs[i2].getMessageBody().toString(); } sms.sendTextMessage(phonenumber, null, message, pi, null); } } } </code></pre> <p>If i am doing anything wrong please let me know. Thanks everyone in advance.</p> <p>Logcat errors</p> <p>06-26 15:49:57.357: ERROR/ContactsProvider(175): Cannot determine the default account for contacts compatibility</p> <p>06-26 15:49:57.357: ERROR/ContactsProvider(175): android.accounts.AuthenticatorException: bind failure</p> <p>06-26 15:49:57.357: ERROR/ContactsProvider(175): at android.accounts.AccountManager.convertErrorToException(AccountManager.java:1437)</p> <p>06-26 15:49:57.357: ERROR/ContactsProvider(175): at android.accounts.AccountManager.access$400(AccountManager.java:138)</p> <p>06-26 15:49:57.357: ERROR/ContactsProvider(175): at android.os.Binder.execTransact(Binder.java:320)</p> <p>06-26 15:49:57.357: ERROR/ContactsProvider(175): at dalvik.system.NativeStart.run(Native Method)</p> <p>There is all my errors.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload