ONVIF 規範基於 **Web Services (SOAP/HTTP)**,Android 客戶端需構造符合 WS-Addressing 的 SOAP 請求發送至攝像機 `/onvif/device_service` 端點。
| 方案 | 優點 | 缺點 |
|---|---|---|
| ksoap2-android | 輕量、無需 NDK、純 Java | 手動構造 SOAP/WS-A 頭繁瑣、易出錯 |
| ONVIF Client Library (GitHub) | 封裝好實體/請求、支持協程 | 需評估維護狀態、依賴大小 |
| NDK + gSOAP / onvif-c | 高性能、C++ 成熟棧、支持設備端 | 需 JNI 橋接、編譯複雜、APK 增大 |
String endpoint = "https://192.168.1.100/onvif/device_service";
SoapObject request = new SoapObject("https://www.onvif.org/ver20/ptz/wsdl", "ContinuousMove");
request.addProperty("ProfileToken", profileToken);
SoObject velocity = new SoapObject("https://www.onvif.org/ver20/ptz/wsdl", "Velocity");
velocity.addProperty("PanTilt", new SoapObject("https://www.onvif.org/ver10/schema", "Vector2D")
.addProperty("x", 0.5f).addProperty("y", 0f).addProperty("space", "https://www.onvif.org/ver10/schema/PanTiltSpeedSpace"));
velocity.addProperty("Zoom", new SoapObject("https://www.onvif.org/ver10/schema", "Vector1D")
.addProperty("x", 0f).addProperty("space", "https://www.onvif.org/ver10/schema/ZoomSpeedSpace"));
request.addProperty("Velocity", velocity);
// WS-Addressing Headers
HttpTransportSE transport = new HttpTransportSE(endpoint, 5000);
List headers = new ArrayList<>();
headers.add(new HeaderProperty("Action", "\"https://www.onvif.org/ver20/ptz/wsdl/ContinuousMove\""));
headers.add(new HeaderProperty("MessageID", "uuid:" + UUID.randomUUID()));
headers.add(new HeaderProperty("To", endpoint));
transport.call(null, envelope, headers);
Google Code 遺產:ONVIF Android 客戶端源碼 (含 PTZ 完整實現)。