Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通过端口接收广播数据\u sms\u_Android_Android Intent_Uri - Fatal编程技术网

Android 通过端口接收广播数据\u sms\u

Android 通过端口接收广播数据\u sms\u,android,android-intent,uri,Android,Android Intent,Uri,我正在编写一个用于测试短信接收器的应用程序。目前,我对将数据SMS接收到特定端口的用例有点困惑。我没有问题发送一个真正的数据短信,但我想只是模拟它通过欺骗广播事件 现在我陷入了困境:我需要在代码中设置意图数据 在XML中,它是这样的 <data android:scheme="sms" android:host="*" android:port="12345" /> intentFilter.addDataScheme("sms"); intentFilter.addD

我正在编写一个用于测试短信接收器的应用程序。目前,我对将数据SMS接收到特定端口的用例有点困惑。我没有问题发送一个真正的数据短信,但我想只是模拟它通过欺骗广播事件

现在我陷入了困境:我需要在代码中设置意图数据

在XML中,它是这样的

<data
  android:scheme="sms"
  android:host="*"
  android:port="12345" />
intentFilter.addDataScheme("sms");
intentFilter.addDataAuthority("*", PORT);
我的问题是如何从上述XML创建正确的URI?

找到了

:/:[| |]

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);