Skip to content
Example on how to connect to an ONVIF camera on Android
Kotlin Java
Branch: master
Clone or download
Guillaume Lagorce
Guillaume Lagorce Bump library version to 1.1.9
Latest commit 608b4b6 Apr 5, 2018

README.md

ONVIFCameraAndroid

Example on how to connect to an ONVIF camera on Android, and dependency to ease the development of an ONVIF Android app.

ONVIF Camera Android

Install with Gradle:

implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.rvirin.onvif:onvifcamera:1.1.6'

Connect to an Onvif camera

currentDevice = OnvifDevice("IP_ADDRESS:PORT", "login", "pwd")
currentDevice.listener = this
currentDevice.getDeviceInformation()

Retrieve the stream URI

class MainActivity : AppCompatActivity(), OnvifListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        currentDevice = OnvifDevice("IP_ADDRESS:PORT", "login", "pwd")
        currentDevice.listener = this
        currentDevice.getDeviceInformation()
    }

// Called by the SDK each time a request is performed on the camera, when the result is parsed
override fun requestPerformed(response: OnvifResponse) {
        Log.d("ONVIF", "Request ${response.request.type} performed.")
        Log.d("ONVIF","Succeeded: ${response.success}, 
		  message: ${response.parsingUIMessage}")

        if (response.request.type == GetDeviceInformation) {
            currentDevice.getProfiles()

        } else if (response.request.type == GetProfiles) {
            currentDevice.getStreamURI()

        } else if (response.request.type == GetStreamURI) {
            Log.d("ONVIF", "Stream URI retrieved: ${currentDevice.rtspURI}")
        }
    }
You can’t perform that action at this time.