Android,mjpeg,http证书

时间:2013-01-21 08:59:20

标签: android certificate raspberry-pi mjpeg

我刚刚开始学习android编程,我也不是那种经验丰富的java。 我试图在android中创建一个应用程序,从raspberry pi流式传输mjpeg(使用mjpeg-streamer)。地址模式是:

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

树莓派部分已经完成。问题出在Android部分..我试过这个代码: Android and MJPEG

然后我得到一个黑屏并且它崩溃..从该页面上的评论,我发现我需要获得http证书或类似..

我尝试了几种解决方案来信任所有证书,但我遇到了一些语法错误。例如,从此页面:https://stackoverflow.com/a/12742591

我说的那条线上有错误(appx第83行):

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

错误是:

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

我不知道如何修复它,因为我是这个主题的新手.Eclipse建议将(X509HostnameVerifier)更改为(HostNameResolver)。但后来我对mjpeg部分的编辑位置感到困惑。

我想我应该改变(appx第29行):

DefaultHttpClient httpclient = new DefaultHttpClient();  

DefaultHttpClient httpclient = HttpsClientBuilder.getBelieverHttpsClient(); 

它仍然崩溃。 除了提到的2行之外,我没有更改上述页面中的任何代码。 有什么建议吗?

我只想信任所有证书,因为当raspberry重新启动时,有时它会更改ip地址。如果IP地址改变了,我必须得到一个新的证书吗?

修改

我忘了为互联网添加使用权限..这是新的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

1 个答案:

答案 0 :(得分:0)

我对http证书一无所知,但是您的日志显示您的应用程序因Caused by: android.os.NetworkOnMainThreadException而崩溃。这意味着您在应用程序主线程上运行网络操作,该线程保留用于处理UI交互。

将您的网络呼叫移至另一个线程或使用AsyncTask类在后台运行网络呼叫以通过此异常。