首页 » 黑莓开发 » 黑莓新浪围脖客户端简单莓中自动判断HTTP连接方法

黑莓新浪围脖客户端简单莓中自动判断HTTP连接方法

6775 1
 static String getConnectionPerameter() {  
             if(Feelsina.connectmode.equalsIgnoreCase("WIFI"))  
                return ";interface=wifi";  
            if(Feelsina.connectmode.equalsIgnoreCase("CMNET"))  
                return ";deviceside=true;apn=cmnet";  
           String connectionParameters = "";  
            if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {  
                // Connected to a WiFi access point  
                connectionParameters = ";interface=wifi";  
            } else {  
                int coverageStatus = CoverageInfo.getCoverageStatus();  
                ServiceRecord record = getWAP2ServiceRecord();  
                if (record != null  
                        && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {  
                    // Have network coverage and a WAP 2.0 service book record  
                    connectionParameters = ";deviceside=true;ConnectionUID="  
                            + record.getUid();  
                } else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {  
                    // Have an MDS service book and network coverage  
                    connectionParameters = ";deviceside=false";  
                } else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {  
                    // Have network coverage but no WAP 2.0 service book record  
                    connectionParameters = ";deviceside=true";  
                }  
            }  
            return connectionParameters;  
        }  
            static ServiceRecord getWAP2ServiceRecord() {  
            ServiceBook sb = ServiceBook.getSB();  
            ServiceRecord[] records = sb.getRecords();  
            for (int i = 0; i < records.length; i++) {  
                String cid = records[i].getCid().toLowerCase();  
                String uid = records[i].getUid().toLowerCase();  
                if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") == -1  
                        && uid.indexOf("mms") == -1) {  
                    return records[i];  
                }  
            }  
            return null;  
            }  
            public static String urlcode(String s) {  
            if (s != null) {  
                try {  
                    s = new String(s.getBytes(), "UTF-8");  
                } catch (UnsupportedEncodingException e) {  
                }  
                StringBuffer tmp = new StringBuffer();  
                try {  
                    for (int i = 0; i < s.length(); i++) {  
                        int b = (int) s.charAt(i);  
                        if ((b >= 0x30 && b <= 0x39) || (b >= 0x41 && b <= 0x5A)  
                                || (b >= 0x61 && b <= 0x7A)) {  
                            tmp.append((char) b);  
                        } else if (b == 0x20) {  
                            tmp.append("+");  
                        } else {  
                            tmp.append("%");  
                            if (b <= 0xf) {  
                                tmp.append("0");  
                            }  
                            tmp.append(Integer.toHexString(b));  
                        }  
                    }  
                } catch (Exception e) {  
                }  
                return tmp.toString();  
            }  
            return null;  
        } 
文章评分1次,平均分5.0

本文原始地址:https://www.tiandiyoyo.com/2011/06/how-to-detect-weibo-http-connection/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

评论前先开启评论开关:


1 Comment

  1. Betty :

    我Lumia上用的驼驼,也是一种新浪微博的客户端
    我觉得很多客户端都比新浪自制的好

载入分页评论...