我正在使用这段代码:
public static MjpegInputStream read(String url) {
HttpResponse res;
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials("admin", "1234"));
try {
res = httpclient.execute(new HttpGet(URI.create(url)));
return new MjpegInputStream(res.getEntity().getContent());
} catch (ClientProtocolException e) { Log.e("MjpegInputStream - CP", e.getMessage()); }
catch (IllegalArgumentException e) { Log.e("MjpegInputStream - IA", e.getMessage()); }
catch (IOException e) { Log.e("MjpegInputStream - IO", e.toString() + " " + e.getMessage()); }
return null;
}
我得到IOExcetion:
04-09 17:27:52.350: E/MjpegInputStream - IO(5749): java.net.SocketException: Permission denied Permission denied
我的 URL 是 http://192.168.1.113/videostream.cgi 当我连接浏览器时,用户名和密码是 (admin, 1234 )
我做错了什么?
更新:
我添加了 INTERNET 权限,现在我的应用程序在这一行崩溃了:
res = httpclient.execute(new HttpGet(URI.create(url)));
带有NetworkOnMainThreadException
最佳答案
你好像忘了加
<uses-permission android:name="android.permission.INTERNET"/>
到您的 list 文件。
关于java - Android 连接到 MJPEG 流 - 权限被拒绝错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10074766/