android.provider.Telephony.Sms.Intents Java Examples

The following examples show how to use android.provider.Telephony.Sms.Intents. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmsSnippet.java    From mobly-bundled-snippets with Apache License 2.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onReceive(Context receivedContext, Intent intent) {
    if (Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
        SnippetEvent event = new SnippetEvent(mCallbackId, SMS_RECEIVED_EVENT_NAME);
        Bundle extras = intent.getExtras();
        if (extras != null) {
            SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
            StringBuilder smsMsg = new StringBuilder();

            SmsMessage sms = msgs[0];
            String sender = sms.getOriginatingAddress();
            event.getData().putString("OriginatingAddress", sender);

            for (SmsMessage msg : msgs) {
                smsMsg.append(msg.getMessageBody());
            }
            event.getData().putString("MessageBody", smsMsg.toString());
            mEventCache.postEvent(event);
            mContext.unregisterReceiver(this);
        }
    }
}
 
Example #2
Source File: SmsSnippet.java    From mobly-bundled-snippets with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@Rpc(description = "Wait for incoming SMS message.")
public JSONObject waitForSms(int timeoutMillis) throws Throwable {
    String callbackId = SMS_CALLBACK_ID_PREFIX + (++mCallbackCounter);
    SmsReceiver receiver = new SmsReceiver(mContext, callbackId);
    mContext.registerReceiver(receiver, new IntentFilter(Intents.SMS_RECEIVED_ACTION));
    return Utils.waitForSnippetEvent(callbackId, SMS_RECEIVED_EVENT_NAME, timeoutMillis)
            .toJson();
}
 
Example #3
Source File: KitkatUtil.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve any SmsMessage objects encoded in the SMS_RECEIVED intent.
 *
 * @param intent An intent passed by Android to the SMS_RECEIVED receiver.
 * @return A list of SmsMessages. The list will be non-null but zero length if the intent lacks
 *   SMS content.
 */
public static List<SmsMessage> getMessagesFromIntent(Intent intent) {
  List<SmsMessage> result = new ArrayList<SmsMessage>();
  SmsMessage[] messages = Intents.getMessagesFromIntent(intent);
  if (messages != null && messages.length >= 0) {
    Collections.addAll(result, messages);
  }
  return result;
}
 
Example #4
Source File: SmsReceiver.java    From coursera-android with MIT License 4 votes vote down vote up
protected void onReceiveWithPrivilege(Context context, Intent intent, boolean privileged) {
    // If 'privileged' is false, it means that the intent was delivered to the base
    // no-permissions receiver class.  If we get an SMS_RECEIVED message that way, it
    // means someone has tried to spoof the message by delivering it outside the normal
    // permission-checked route, so we just ignore it.
    if (!privileged && intent.getAction().equals(Intents.SMS_RECEIVED_ACTION)) {
        return;
    }

    intent.setClass(context, SmsReceiverService.class);
    intent.putExtra("result", getResultCode());
    beginStartingService(context, intent);
}
 
Example #5
Source File: SmsSnippet.java    From mobly-bundled-snippets with Apache License 2.0 3 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@AsyncRpc(description = "Async wait for incoming SMS message.")
public void asyncWaitForSms(String callbackId) {
    SmsReceiver receiver = new SmsReceiver(mContext, callbackId);
    mContext.registerReceiver(receiver, new IntentFilter(Intents.SMS_RECEIVED_ACTION));
}
 
Example #6
Source File: PromptToSetAsDefaultMessageAppActivity.java    From medic-gateway with GNU Affero General Public License v3.0 2 votes vote down vote up
public void openDefaultMessageAppSettings(View v) {
	Intent i = new Intent(Intents.ACTION_CHANGE_DEFAULT);
	i.putExtra(Intents.EXTRA_PACKAGE_NAME, getPackageName());
	startActivityForResult(i, REQUEST_CHANGE_DEFAULT_MESSAGING_APP);
}