我试图在android中运行以下代码
URLConnection l_connection = null;
// Create connection
uzip=new UnZipData(mContext);
l_url = new URL(serverurl);
if ("https".equals(l_url.getProtocol())) {
System.out.println("<<<<<<<<<<<<< Before TLS >>>>>>>>>>>>");
sslcontext = SSLContext.getInstance("TLS");
System.out.println("<<<<<<<<<<<<< After TLS >>>>>>>>>>>>");
sslcontext.init(null,
new TrustManager[] { new CustomTrustManager()},
new java.security.SecureRandom());
HttpsURLConnection
.setDefaultHostnameVerifier(new CustomHostnameVerifier());
HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext
.getSocketFactory());
l_connection = (HttpsURLConnection) l_url.openConnection();
((HttpsURLConnection) l_connection).setRequestMethod("POST");
} else {
l_connection = (HttpURLConnection) l_url.openConnection();
((HttpURLConnection) l_connection).setRequestMethod("POST");
}
/*System.setProperty("http.agent", "Android_Phone");*/
l_connection.setConnectTimeout(10000);
l_connection.setRequestProperty("Content-Language", "en-US");
l_connection.setUseCaches(false);
l_connection.setDoInput(true);
l_connection.setDoOutput(true);
System.out.println("<<<<<<<<<<<<< Before Connection >>>>>>>>>>>>");
l_connection.connect();
Run Code Online (Sandbox Code Playgroud)
在l_connection.connect()
,它给出了这个SSLhandshakeException.有时候它有效,但大部分时间它都有例外.它只发生在Android 4.0模拟器上.我在Android 4.4和5.0上测试过,它运行正常.可能是什么原因造成的?请帮忙
堆栈跟踪
04-28 15:51:13.143: W/System.err(2915): javax.net.ssl.SSLHandshakeException: …
Run Code Online (Sandbox Code Playgroud) ssl android sslhandshakeexception android-4.0.3-ice-cream-sandwich
我需要用Android 4.0.3测试我的Android应用程序,但我无法用这个Android版本创建一个模拟器.请查看以下截图以获取更多详细信息:
已经尝试过没有运气了:
我该如何解决这个问题?
编辑:
正如BrentM所建议的那样,我尝试使用android命令行工具创建它.它已成功创建,但当我尝试从Android Studio编辑它时,它会出错:指定的图像文件必须是有效的图像文件.
系统中图像文件的地址:/ Android/Sdk/system-images/android-15/x86
android android-emulator android-studio android-4.0.3-ice-cream-sandwich