rvi / ONVIFCameraAndroid

Example on how to connect to an ONVIF camera on Android
MIT License
142 stars 68 forks source link

getServices problem on api26 or higher #19

Closed LeandroVanolli closed 3 years ago

LeandroVanolli commented 3 years ago

Hello folks! I'm developping an App to stream IP cameras. I'm using the 1.1.8 version of the onvif library (but I also tried the 1.1.6).

When it runs on my Zenfone5 with Android 5 (API 21), I receive the "RESULT: true" followed by the device's profiles. Until here, everything looks fine. When I run it on Android 10 and Android 9, I just receive the "RESULT: false". No messages are returned, by the way. If someone could help, I'll be glad!

class MainActivity : AppCompatActivity(), OnvifListener {

    //var vlcVideoLibrary: VlcVideoLibrary? = null

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

        currentDevice = OnvifDevice("192.168.1.100", "admin", "tecnnic2001")
        currentDevice.listener = this
        currentDevice.getServices()
override fun requestPerformed(response: OnvifResponse) {
        Log.d("Aplicativo: ", response.parsingUIMessage)

        Log.d("ONVIF", "Request ${response.request.type} performed.")
        Log.d("ONVIF","Succeeded: ${response.success}, message: ${response.parsingUIMessage}")

Here's my log: image

LeandroVanolli commented 3 years ago

Solved!

Api 27 or higher, Android defaults the use of Cleartext to false. As this lib uses cleartext on http requests, we need to place this line on manifest, on application stack: android:usesCleartextTraffic="true"

Source: https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic