1

I just start to learn android programming and I'm not that experienced in java either. I am trying to make an application in android that stream a mjpeg from raspberry pi (using mjpeg-streamer). The address pattern is:

http://ip_address:8080/?action=stream

The raspberry pi part is finished. The problem is in the Android part.. I tried the code from this one: Android and MJPEG

and then i got a black screen and it crash.. from the comments on that page, i found that i need to get the http certificates or such..

I tried several solutions to trust all certificates but i got some syntax errors. For example, from this page: https://stackoverflow.com/a/12742591

i got an error on the line where it says (appx line 83):

super(null, null, null, null, null, (X509HostnameVerifier)null);

The error is:

The constructor SSLSocketFactory(null, null, null, null, null, X509HostnameVerifier) is undefined

And I don't know how to fix it since i'm new on this topic.. Eclipse suggest to change (X509HostnameVerifier) to (HostNameResolver). But then I got confused on where to edit in the mjpeg part.

I think I should change (appx line 29):

DefaultHttpClient httpclient = new DefaultHttpClient();  

to

DefaultHttpClient httpclient = HttpsClientBuilder.getBelieverHttpsClient(); 

It still crash. I didn't change any of the code from the pages above except that 2 lines mentioned. Any suggestion?

I just want to trust all certificates, since when the raspberry pi restart, sometime it change the ip address. If the ip address change, I have to get a new certificates right?

Edit

I forgot to add uses permission for internet.. this is the new logcat:

01-21 18:02:48.825: W/dalvikvm(27150): threadid=1: thread exiting with uncaught exception (group=0x40c4d1f8)
01-21 18:02:48.830: E/AndroidRuntime(27150): FATAL EXCEPTION: main
01-21 18:02:48.830: E/AndroidRuntime(27150): java.lang.RuntimeException: Unable to start activity : android.os.NetworkOnMainThreadException
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1973)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1999)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.os.Looper.loop(Looper.java:137)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.ActivityThread.main(ActivityThread.java:4513)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at java.lang.reflect.Method.invokeNative(Native Method)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at java.lang.reflect.Method.invoke(Method.java:511)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:974)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:741)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at dalvik.system.NativeStart.main(Native Method)
01-21 18:02:48.830: E/AndroidRuntime(27150): Caused by: android.os.NetworkOnMainThreadException
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at libcore.io.IoBridge.connectErrno(IoBridge.java:138)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at libcore.io.IoBridge.connect(IoBridge.java:112)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at java.net.Socket.connect(Socket.java:842)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at com.example.testviewer.MjpegInputStream.read(MjpegInputStream.java:31)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at com.example.testviewer.MjpegSample.onCreate(MjpegSample.java:40)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.Activity.performCreate(Activity.java:4465)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-21 18:02:48.830: E/AndroidRuntime(27150):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
01-21 18:02:48.830: E/AndroidRuntime(27150):    ... 11 more
01-21 18:02:57.795: I/Process(27150): Sending signal. PID: 27150 SIG: 9
Community
  • 1
  • 1
lukrina
  • 11
  • 2

1 Answers1

0

I don't have any idea about the http certificates but your log shows that your application is crashing because of Caused by: android.os.NetworkOnMainThreadException . This means you are running your network operations on the application main thread which is reserved for handling UI interactions.

Move your network call to another thread or use AsyncTask class to run the network calls in the background to get past this exception.

Supreethks
  • 597
  • 6
  • 16