Detecting and Using LTE Networks

3GPP Long Term Evolution (LTE) is a 4G wireless network technology that supports significantly higher data rates than those supported by existing 3G networks. Because LTE enables video applications on both the downlink and the uplink, Android-powered devices that support LTE on Verizon Wireless—such as DROID BIONIC—are able to provide fast, high-quality web browsing, video streaming, and video conferencing. And because these devices also support traditional 3G (CDMA) and eHRPD (evolved High-Rate Packet Data) networks, the device isn’t limited to operating within LTE coverage areas. Users get the best of all worlds: the greatest degree of coverage and the best network performance possible within a given cell.

Working in conjunction with Verizon Wireless, Motorola Mobility has implemented a few Android platform extensions to enable LTE and eHRPD on DROID BIONIC and certain other Android-powered devices intended for use on the Verizon Wireless network. This article describes how Android applications can detect when the device is on the LTE and eHRPD networks, and how they can be notified when the connected network type changes.

Detecting the Network
Devices on the Verizon Wireless LTE network typically maintain a separate connection each for voice and data. An Android application uses the Connectivity Manager to monitor the state of the data network. Similarly, the Telephony Manager provides APIs that enable apps to check the state of the voice connection.

When writing Android applications that make use of a specific feature, you typically add a corresponding <uses-feature> element to your AndroidManifest.xml file. Apps that interact with the telephony features typically include:

<uses-feature android:name="android.hardware.telephony"/>

 

Apps that specifically use the LTE and/or eHRPD capabilities of a device should include one or both of the following:

<uses-feature android:name="android.hardware.telephony.lte"/>view sourceprint?
<uses-feature android:name="android.hardware.telephony.ehrpd"/>

 

In addition, you’ll need ACCESS_NETWORK_STATE permission:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

 

Data Connection
Using the Connectivity Manager, check the active network type to see whether or not the data connection is 4G. Obtain the NetworkInfo object from an instance of the Connectivity Manager. Then, from the NetworkInfo object get the network type and subtype.

// get the type and subtype of the data connection
ConnectivityManager connMgr =
    (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connMgr.getActiveNetworkInfo();
int dNetType = netInfo.getType();
int dNetSubtype = netInfo.getSubtype();

 

Depending upon the network to which the device is currently connected, the values listed in the following tables are returned when you query the NetworkInfo object:

Function Return Value (LTE)
getType() 0 (ConnectivityManager.TYPE_MOBILE)
getSubtype() 13
getSubtypeName() “LTE”

 

Function Return Value (eHRPD)
getType() 0 (ConnectivityManager.TYPE_MOBILE)
getSubtype() 14
getSubtypeName() “eHRPD”

 

Function Return Value (CDMA)
getType() 0 (ConnectivityManager.TYPE_MOBILE)
getSubtype() 6
getSubtypeName() “CDMA - EvDo rev. A”

 

Similar values are returned for the NetworkInfo objects in the array returned by the Connectivity Manager’s getAllNetworkInfo() method.

Voice Connection
To determine the network currently being used for the voice connection, simply request the network type from an instance of the TelephonyManager object:

TelephonyManager telMgr =
    (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
int vNetType = telMgr.getNetworkType();
if(vNetType == NETWORK_TYPE_LTE){
    // on the LTE voice network
}

 

The following table lists return values from the getNetworkType() method, depending upon the current network:

Network getNetworkType() return value
LTE 13 (NETWORK_TYPE_LTE)
eHRPD 14 (NETWORK_TYPE_EHRPD)
CDMA 6 (NETWORK_TYPE_EVDO_A)

Handling Network Transitions
As the connected device moves from cell to cell, it tries to maintain its network connection. It will generally be successful if the network type doesn’t change between cells. However, if the device moves into or out of the 4G coverage area, the data connection will be dropped and your IP address will change. Because this can happen while an app has an active data connection open, Android sends an android.net.ConnectivityManager.CONNECTIVITY_ACTION broadcast whenever there is a change in the network. If your app needs to be aware of network changes, register for this broadcast. When Android sends a CONNECTIVITY_ACTION broadcast, it includes extra data: a NetworkInfo object for the new network. Consult this NetworkInfo object to see what kind of connectivity event occurred.

private class ConnectivityRcvr extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction()
                .equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            NetworkInfo netInfo =
                (NetworkInfo)intent.getParcelableExtra(ConnectivityManager
                    .EXTRA_NETWORK_INFO);
            int netType = netInfo.getType();
            int netSubtype = netInfo.getSubtype();
            boolean isConnected = netInfo.isConnected();
            // ...
        }
        // ...
    }
}


Typically you register for the CONNECTIVITY_ACTION broadcast either in your onCreate() method (if you prefer to register from within your app’s source code) or in your AndroidManifest.xml file.

Note that there is a similar broadcast intent defined in the TelephonyManager: ACTION_PHONE_STATE_CHANGED is broadcast if the call state changes. Be aware that your app will need READ_PHONE_STATE permission when registering for this broadcast.

 

//

 

https://developer.motorola.com/docstools/library/detecting-and-using-lte-networks/

 

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        this.connectivityBroadcastReceiver = new ConnectivityBroadcastReceiver();
        this.registerReceiver(this.connectivityBroadcastReceiver, intentFilter);

 

 

        this.unregisterReceiver(this.connectivityBroadcastReceiver);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值