91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

通過Broadcast動態注冊監聽網絡變化和網絡類型

發布時間:2020-07-18 10:20:58 來源:網絡 閱讀:334 作者:jdijfijf 欄目:移動開發


package com.beini.networkchanges;


import android.app.Activity;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.net.ConnectivityManager;

import android.net.NetworkInfo;

import android.os.Bundle;

import android.telephony.TelephonyManager;

import android.util.Log;

import android.widget.TextView;


/**

 * 

 * @author beini

 * 

 */

public class MainActivity extends Activity {


private NetworkChangeReceive networkChangeReceive;

private TextView txtShowNetWorkeSate;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

txtShowNetWorkeSate = (TextView) findViewById(R.id.txt_showNetWorkeSate);

inintReceiver();

}


private void inintReceiver() {

IntentFilter intentFilter = new IntentFilter();

intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");

networkChangeReceive = new NetworkChangeReceive();

registerReceiver(networkChangeReceive, intentFilter);


}


class NetworkChangeReceive extends BroadcastReceiver {


@Override

public void onReceive(Context context, Intent intent) {

ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo networkInfo = connectivityManager

.getActiveNetworkInfo();

if (networkInfo != null && networkInfo.isAvailable()) {

txtShowNetWorkeSate.setText(getString(R.string.net_aviable)

+ getNetWorkType(networkInfo));

} else {

txtShowNetWorkeSate.setText(getString(R.string.net_unaviable));

}

}

}


@Override

protected void onDestroy() {

super.onDestroy();

unregisterReceiver(networkChangeReceive);

}


/**

* 獲取網絡 2g,3g, 4g;通過networkInfo .getSubtype()會得到網絡的類型,

* 用networkInfo.getSubtypeName()會得到網絡的名字。

*/

public String getNetWorkType(NetworkInfo networkInfo) {

// int subType = networkInfo.getSubtype();

// String subTypeName = networkInfo.getSubtypeName();

//

int type = networkInfo.getType();

// String typeName = networkInfo.getTypeName();

//

// Log.i("beini", "subType=" + type + "   " + "typeName=" + typeName);

// Log.i("beini", "subType=" + subType + "   " + "subTypeName="

// + subTypeName);

if (type == ConnectivityManager.TYPE_WIFI) {

return getString(R.string.net_wifi);

} else if (type == ConnectivityManager.TYPE_MOBILE) {

return getnetworkChange();

}

return "";

}


public String getnetworkChange() {

TelephonyManager mTelephonyManager = (TelephonyManager) getApplication()

.getSystemService(Context.TELEPHONY_SERVICE);

int networkType = mTelephonyManager.getNetworkType();

switch (networkType) {

case TelephonyManager.NETWORK_TYPE_GPRS:

case TelephonyManager.NETWORK_TYPE_EDGE:

case TelephonyManager.NETWORK_TYPE_CDMA:

case TelephonyManager.NETWORK_TYPE_1xRTT:

case TelephonyManager.NETWORK_TYPE_IDEN:

return "2G";

case TelephonyManager.NETWORK_TYPE_UMTS:

case TelephonyManager.NETWORK_TYPE_EVDO_0:

case TelephonyManager.NETWORK_TYPE_EVDO_A:

case TelephonyManager.NETWORK_TYPE_HSDPA:

case TelephonyManager.NETWORK_TYPE_HSUPA:

case TelephonyManager.NETWORK_TYPE_HSPA:

case TelephonyManager.NETWORK_TYPE_EVDO_B:

case TelephonyManager.NETWORK_TYPE_EHRPD:

case TelephonyManager.NETWORK_TYPE_HSPAP:

return "3G";

case TelephonyManager.NETWORK_TYPE_LTE:

return "4G";

default:

return "Unknown";

}

}

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

鸡泽县| 大化| 兰州市| 云安县| 锦屏县| 闽清县| 崇义县| 四平市| 凭祥市| 孝义市| 开原市| 蓝山县| 安平县| 林芝县| 岱山县| 榆社县| 阳江市| 托克逊县| 昌邑市| 永修县| 葵青区| 吴川市| 呼和浩特市| 应用必备| 石首市| 常德市| 大姚县| 新津县| 凭祥市| 庆元县| 曲沃县| 哈巴河县| 晴隆县| 南漳县| 绍兴市| 马边| 炉霍县| 定安县| 灵宝市| 娱乐| 洛阳市|