Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One way of feeding a string to the emulator would be to implement a BroadcastReceiver for SMS messages. Then from a DOS box you could '<strong>telnet localhost 5554</strong>' (or whatever number your emulator starts up as) Then you can use the emulator command <strong>sms send 1234 yourString</strong>. (1234 is just a dummy for the 'sending' phone number.</p> <p>You would have to parse the string inside the receiver to make it alter different class member variables etc or whatever.</p> <p>It's a pretty clunky method but it wouldn't impact your UI and it would only need a dozen or so lines of code for the receiver.</p> <p>I just stuck this bit of code into onCreate and set a breakpoint to test the principle</p> <pre><code> rcvIncoming = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String message = ""; Bundle data = intent.getExtras(); if (data != null) { Object pdus[] = (Object[]) data.get("pdus"); String sender = null; for (Object pdu : pdus) { SmsMessage part = SmsMessage.createFromPdu((byte[]) pdu); message += part.getDisplayMessageBody(); if (sender == null) { sender = part.getDisplayOriginatingAddress(); } } } String test = message;// breakpoint here to test } }; registerReceiver(rcvIncoming, new IntentFilter( "android.provider.Telephony.SMS_RECEIVED")); </code></pre> <p>you'll need this in the manifest too:</p> <pre><code> &lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt; </code></pre> <p>.</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