# \[Android\] - IPCapture library problem

**URL:** <https://discourse.processing.org/t/android-ipcapture-library-problem/41615>\
**Category:** Processing for Android\
**Created:** [April 5, 2023, 3:49am UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615 "2023-04-05T03:49:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [April 5, 2023, 3:49am UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/1 "2023-04-05T03:49:31Z")

</div>

[Android] - ipcapture library problem

hello. Nice to meet you.

```auto
step-7
run-1
run-2
run-3
(HTTPLog)-Static: isSBSettingEnabled false
(HTTPLog)-Static: isSBSettingEnabled false
Unable to open I/O streams (app): http://20....

```

An error occurs as above.

![abc](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/6/e6f8245a6abbb281699346f5e137c254df87540b.jpeg)

```auto
    try {
      conn = (HttpURLConnection)url.openConnection();
      String user = "admin"; String pass = "jusung_123";
      conn.setRequestProperty("Authorization", "Basic " + base64.encode(user + ":" + pass));
    }
    catch (IOException e) {
      System.err.println("Unable to connect: " + e.getMessage());
      return;
    }
    System.out.println("run-3");
    
    try {
      // int p_value = 8192; // p_value = 8192;
      httpIn = new BufferedInputStream(conn.getInputStream(), p_value);
      jpgOut = new ByteArrayOutputStream(p_value);      
    }
    catch (IOException e) {
      
      System.err.println("Unable to open I/O streams(app): " + e.getMessage());
      return;
    }
    System.out.println("run-4");

```

Does anyone know the cause of the error?

help me~.

1. It works fine on PC.
2. It doesn’t work in the app.  
Why?

```auto
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package=""><uses-sdk android:minSdkVersion="15" android:targetSdkVersion="29"/><application android:debuggable="true" android:icon="@drawable/icon" android:label="CCTV" android:requestLegacyExternalStorage="true" android:targetSandboxVersion="2" android:usesCleartextTraffic="true">
<activity android:name=".MainActivity">android:theme="@android:style/Theme.NoTitleBar"&gt;<intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/><uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/></manifest>

```

link : [Android 9 파이에서 http 사용시 에러 발생 해결](https://mrgamza.tistory.com/639)

android android:networksecurityconfig  
I would like to add the above,  
It is not added in ‘Processing’.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [April 5, 2023, 1:28pm UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/2 "2023-04-05T13:28:46Z")

</div>

I tried to work on it today, but I didn’t succeed.  
Why is that?  
The current phenomenon is as follows.

1. CCTV Hikvision Model

- PC(JAVA Mode) : Work
- SmartPhone(Android Mode) : Work

1. CCTV H Model

- PC(JAVA Mode) : Work
- Smartphone(Android Mode) : not Work

I don’t understand this part too much.  
Also, ‘H Model CCTV’ is not visible even when ‘network streaming’ is performed through VLC media.

Both PC and Android have the same source code, but why does the operation differ depending on the ‘CCTV Model’?

```auto
       conn = (HttpURLConnection)url.openConnection();
       // conn.setRequestProperty("Authorization", authorizationHeaderValue);
       
        System.out.println("run-2-1");        
       //conn.setRequestMethod("GET");
       //conn.setRequestProperty("Origin", "http://211.104.181.146:10111");   
       //conn.setRequestProperty("Accept", "application/xml");
       //conn.setRequestProperty("Content-Type", "text/html"); //
       
       // conn.setDoOutput(true);
       // conn.setDoInput(true);           
        System.out.println("Status code: " + conn.getResponseCode());
        System.out.println("Message: " + conn.getResponseMessage());

```

Error MSG(println)

> Status code: 401  
> Message: Unauthorized

Are there any seniors? help me~.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [April 6, 2023, 2:50am UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/3 "2023-04-06T02:50:55Z")

</div>

```auto
 conn = null;
 conn = (HttpURLConnection)url.openConnection();
 System.out.println("---------------------------------------------------");
 System.out.println(" conn : " + conn.toString());
 System.out.println("---------------------------------------------------");

```

What I’ve experienced so far  
It seems to prevent it when requesting from CCTV to Android. (This is my opinion.)

> // JAVA(PC)  
> conn: sun.net.www.protocol.http.HttpURLConnection:[http://ip/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10](http://ip/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10)

> // Android (Smartphone)  
> conn: com.android.okhttp.internal.huc.HttpURLConnectionImpl:[http://ip/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10](http://ip/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10)

The result is as above.  
By any chance, while running on Android  
Can I send a PC request to CCTV?  
Can’t I force CCTV to send the information that I am a computer, not a smartphone?

 ![fig](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/f/5f0860fb89c07ff077d22018718f627ecc99c57b.jpeg)

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [April 6, 2023, 9:05am UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/4 "2023-04-06T09:05:47Z")

</div>

The results of what I have done so far are as follows.  
CCTV Model No. 2

- It must be ‘Digest authentication processing’ using ‘md5’.

It’s pretty tough.

```auto
DESCRIBE rtsp://192.168.9.100:554/profile2/media.smp RTSP/1.0
CSeq: 2
Authorization: Digest
username="admin",realm="iPOLiS",nonce="C9AB5CEC50A78C07C25704A9675B171E",uri
="rtsp://192.168.9.100:554/profile2/media.smp",cnonce="814ae708b84f4f0f9f2e5
1fe1624166d",nc=00000001,response="40899fab43a5df53c72f8b3683f023e2",qop="au
th"
User-Agent: oscar-rtsp-client
Require: Bestshot

```

---

<div class="post-metadata">

**Author:** ![JoseMY](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josemy/32/2016_2.png) [@JoseMY](https://discourse.processing.org/u/JoseMY)\
**Post date:** [April 9, 2023, 8:53pm UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/5 "2023-04-09T20:53:51Z")

</div>

Hi!

I don’t know if posting credentials is good practice, but at least they take to a private ip not reachable from outside.

About your question, chances are there is a different android version on the non-working machine. Different android versions imply different APIs.

Another possible source of conflict are permissions. Make sure the app is requesting permissions to user, user is granting them and “Google Play Protection” is not removing permissions. It tends to revoke permissions even when instructed not to do so.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [April 9, 2023, 9:26pm UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/6 "2023-04-09T21:26:09Z")

</div>

Both urls may be opened on an Android device if they are opened by a browser. The failure occurs when the urls are opened in a java app (only one will open on my system in Android mode; neither will open in Java mode on my system). According to this reference (second answer) that is a feature of java apps: [https://stackoverflow.com/questions/32306509/server-returned-http-response-code-401-for-url-when-using-shopify-api](https://stackoverflow.com/questions/32306509/server-returned-http-response-code-401-for-url-when-using-shopify-api) .

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [April 9, 2023, 11:10pm UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/7 "2023-04-09T23:10:51Z")

</div>

@JoseMY / @svan

- It must be ‘Digest authentication processing’ using ‘md5’.

The reason is as above. If you do it with an internet browser, the authentication is said to be automatic.  
However, in order to weave with Android or a separate WEB code  
It must be ‘Digest authentication processing’ using ‘md5’.  
The above protocol must be followed.

Because ‘IPCaputure library’ has Basic authentication system, ‘corresponding CCTV’ does not operate.  
However, as a result of contacting CCTV, it is automatically authenticated when connected to the OS, but when using a separate ‘iOS, Android, make WEB’, ‘md5’ authentication system is required.

Thank you for your interest.  
And, as far as I know, iOS is easy to implement. However, Android is quite difficult to implement the above.

@svan // Please delete the image. You will see the CCTV URL. please.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [April 9, 2023, 11:45pm UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/8 "2023-04-09T23:45:41Z")

</div>

> Please delete the image.

No problem. It’s also visible in your second post, so I thought you didn’t care.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [April 10, 2023, 4:55am UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/9 "2023-04-10T04:55:45Z")

</div>

As a workaround you could launch your android device browser from a Processing app then enter your username and password when prompted. It takes very little code and does work.

```auto
import android.content.Intent;
import android.net.Uri;

void setup() {
  fullScreen();
  Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://xxx.xxx.xxx.xxx:yyyyy/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10"));
  startActivity(intent);
}

```

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [April 10, 2023, 5:32am UTC](https://discourse.processing.org/t/android-ipcapture-library-problem/41615/10 "2023-04-10T05:32:12Z")

</div>

@svan

Thank you for your attention. you are right.  
It is very difficult to get certified on your own.

So, in the past, the ‘RTSP’ method was implemented as follows.

> [@Processing is related to Android mode 'RTSP (RTP, SDP)'. Help me](https://discourse.processing.org/t/processing-is-related-to-android-mode-rtsp-rtp-sdp-help-me/11215/16):
>
> Yes please. Show that part of the code!

However, if you use it like that, you cannot process images within the ‘Android APP’.

There are many ways.

1. ‘Digest authentication processing(Android)’ using ‘md5’. protocol implementation

- but, very difficult.

1. Create a separate streaming server and implement it as http server ‘basic authentication’

- difficult.

1. Receive RTSP address and implement ‘online http server’. ‘basic authentication’

- exam site : [Flashphoner Web Call Server](https://demo.flashphoner.com/admin/login.html) (Paid site)
