[android] 網路連結類型和渠道,android渠道

來源:互聯網
上載者:User

[android] 網路連結類型和渠道,android渠道

1.實現方式

1.1使用HttpUrlConnection

1.2使用HttpClient

1.3使用Socket,比如:豌豆莢,聊天工具

 

2.通訊渠道

2.1 WLAN(wi-fi),100米左右的資料轉送

2.2 手機APN存取點(基站)

2.2.1 wap的方式,中國特色,首先會串連電信電訊廠商代理攔截10.0.0.172,HttpUrlConnection會不穩定

2.2.2 net的方式

 

3.通訊工具

3.1判斷網路類型

根據Context上下文,判斷是wifi還是APN,然後再判斷APN的接入方式,有代理資訊的是wap沒有的是net

package com.tsh.lottery.net;import android.content.ContentResolver;import android.content.Context;import android.database.Cursor;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.net.Uri;public class NetUtils {    /**     * 擷取網路狀態     * @param context     * @return     */    public static String getNetworkInfo(Context context) {        ConnectivityManager cm=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);        //判斷wifi        NetworkInfo networkInfo=cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);        if(networkInfo!=null && networkInfo.isConnected()){            return "wifi";        }        //判斷APN        NetworkInfo mobileInfo=cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);        if(mobileInfo!=null && mobileInfo.isConnected()){            //擷取APN接入方式,因為許可權問題,沒有成功//            ContentResolver resolver=context.getContentResolver();//            Cursor cursor=resolver.query(Uri.parse("content://telephony/carriers"), null, null, null, null);//            if(cursor!=null && cursor.moveToFirst()){//                String proxy=cursor.getString(cursor.getColumnIndex("proxy"));//                System.out.println(proxy);//            }            return "mobile";        }        return "no";    }}

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.