3

I'm trying to create place search functionality in my app using GoogleMap's api for Android. I want to fill AutoComplete TextView as user types the name of the place. But I'm getting this Excetion while calling urlConnection.connect(); statement:

javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb911cd50: Failure in SSL library, usually a protocol error
error:1407743E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:765 0xae688edd:0x00000000)

Following is the code I'm using:

private String downloadUrl(String strUrl) throws IOException {
    String data = "";
    InputStream iStream = null;
    HttpURLConnection urlConnection = null;
    try {
        URL url = new URL(strUrl);

        // Creating an http connection to communicate with url
        urlConnection = (HttpURLConnection) url.openConnection();

        // Connecting to url
        urlConnection.connect();

        // Reading data from url
        iStream = urlConnection.getInputStream();

        BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

        StringBuffer sb = new StringBuffer();

        String line = "";
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }

        data = sb.toString();

        br.close();

    } catch (Exception e) {
        Log.d("Exception while downloading url", e.toString());
    } finally {
        iStream.close();
        urlConnection.disconnect();
    }
    return data;
}

private String getPlacesUrl(String qry) {
        try {
            qry = "input=" + URLEncoder.encode(qry, "utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }

        // Sensor enabled
        String sensor = "sensor=false";


        // place type to be searched
        String types = "types=geocode";

        // Building the parameters to the web service
        String parameters = qry + "&" + types + "&" + sensor + "&" + mKey;

        // Output format
        String output = "json";


        // Building the url to the web service
        String url = "https://maps.googleapis.com/maps/api/place/autocomplete/" + output + "?" + parameters;

        return url;
    }

I've registered my apps package and SHA1 of my system in google console. The url that I'm getting after calling getPlaceUrl() method is of this type:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=b&types=geocode&sensor=false&key=API_KEY

Please help me fix the issue.

4
  • see stackoverflow.com/questions/20741405/…. might be helpful Commented May 11, 2015 at 10:01
  • @shayanpourvatan here the server is GoogleMap's Server. I don't think TLS 1.0 protocol support is not there Commented May 11, 2015 at 10:05
  • What device/API level do you execute the code? The SSL/TLS protocols and ciphers depend on the used OS. Commented May 11, 2015 at 11:44
  • @Robert I'm executing code on Lollypop/Kitkat devices, I'm using API level 19 for compiling the source Commented May 11, 2015 at 12:47

1 Answer 1

0

I got a almost same issue. My logcat as follows:

javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x60b486b8: Failure in SSL library, usually a protocol error SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:744 0x5ea50d74:0x00000000)

Finally, I found a solution it's to modify httpURLConnection.setHostnameVerifier HostnameVerifier verify return value from false to true, but I don't know the root cause. Is there any one can supply tips?

        httpURLConnection.setHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                // TODO Auto-generated method stub
                // return false;
                return true;
            }
        });
Sign up to request clarification or add additional context in comments.

1 Comment

you probably mean HttpsURLConnection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.