List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Friday, June 10, 2016

Blackberry get IP Address

    String ip = new String("");

    try {
        int cni = RadioInfo.getCurrentNetworkIndex();
        int apnId = cni + 1;
        byte[] ipaddr = RadioInfo.getIPAddress(apnId);
        for (int i = 0; i < ipaddr.length; i++) {
        int temp = (ipaddr[i] & 0xff);
        if (i < 3) {
            ip = ip.concat("" + temp + ".");
        } else {
            ip = ip.concat("" + temp);
        }
        }
        System.out.println("ipaddress " + ip);
    } catch (Exception e) {
        ip = null;
    }

Blackberry Get User Address from Lattitude and Longitude

  getLocationFromGoogleMaps(43.4631,-80.5207);

  private static void getLocationFromGoogleMaps(double _lattitude, double _longitude) {

    String fullAddress = "";
    HttpConnection conn = null;
    InputStream in = null;
    ByteArrayOutputStream out = null;
    try {
        String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + _lattitude + "," + _longitude;
        conn = (HttpConnection) Connector.open(url, Connector.READ);
        conn.setRequestMethod(HttpConnection.GET);
        int code = conn.getResponseCode();
        if (code == HttpConnection.HTTP_OK) {
        in = conn.openInputStream();
        out = new ByteArrayOutputStream();
        byte[] buffer = new byte[in.available()];
        int len = 0;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer);
        }
        out.flush();
        String response = new String(out.toByteArray());
        JSONObject resObject = new JSONObject(response);
        JSONArray result = resObject.getJSONArray("results");

        if (result.length() > 0) {
            JSONObject dict = result.getJSONObject(0);
            System.out.println("**Resp :**" + dict.getString("formatted_address"));
            fullAddress = dict.getString("formatted_address");
            Dialog.alert(fullAddress);
        } else {
           //error
        }

        }
    } catch (Exception e) {
        Dialog.alert(e.getMessage());
       }

    }