Broadcast data_sms_received with port

I am writing an application used to test SMS receivers. I am currently a bit stuck with a use case for getting SMS data for a specific port. I have no problem sending real SMS data, but I would like to just simulate it by emitting a broadcast event.

Now that I'm stuck: I need to set intent data in code.

In XML it looks like

<data
  android:scheme="sms"
  android:host="*"
  android:port="12345" />

      

The intent filter it should match is built like this

intentFilter.addDataScheme("sms");
intentFilter.addDataAuthority("*", PORT);

      

My question is, how do I generate the correct URI from the above XML?

+3


source to share


1 answer


Found a solution

<scheme>://<host>:<port>[<path>|<pathPrefix>|<pathPattern>]



Uri dataUri = Uri.parse("sms://*:"+port);
        Intent intent = new Intent();
        intent.setAction("android.intent.action.DATA_SMS_RECEIVED")
                .putExtra("pdus", new Object[]{pdu})
                .setDataAndNormalize(dataUri);

      

+1


source







All Articles