How to detect network type change from 3G to H + on Android

using connectivitymanager and broadcast receiver I can get connect and disconnect events as explained by Eric post here

What I would like to know is the type change when the network connects. Example: from 3G to H + and vice versa. I can see that there are no events inside OnReceive (..) when this change happens ...

User case for clarity: step1: 3G connection enabled, events received in broadcast (BCR) and handled step2: start a call, change the connection from 3G to h +, but there is no event in BCR.

expected result: wait for events in BCR when changing from 3G to h + or Edge ...

+3


source to share


1 answer


Here in the switch statement you can do some taks. Thread can call the following code and monitor the network.

Get network type

TelephonyManager teleMan =   
            (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
int networkType = teleMan.getNetworkType(); 

switch (networkType) 
{ 
case 7: 
    textV1.setText("1xRTT"); 
    break;       
case 4: 
    textV1.setText("CDMA"); 
    break;       
case 2: 
    textV1.setText("EDGE"); 
    break;   
case 14: 
    textV1.setText("eHRPD"); 
    break;       
case 5: 
    textV1.setText("EVDO rev. 0"); 
    break;   
case 6: 
    textV1.setText("EVDO rev. A"); 
    break;   
case 12: 
    textV1.setText("EVDO rev. B"); 
    break;   
case 1: 
    textV1.setText("GPRS"); 
    break;       
case 8: 
    textV1.setText("HSDPA"); 
    break;       
case 10: 
    textV1.setText("HSPA"); 
    break;           
case 15: 
    textV1.setText("HSPA+"); 
    break;           
case 9: 
    textV1.setText("HSUPA"); 
    break;           
case 11: 
    textV1.setText("iDen"); 
    break; 
case 13: 
    textV1.setText("LTE"); 
    break; 
case 3: 
    textV1.setText("UMTS"); 
    break;           
case 0: 
    textV1.setText("Unknown"); 
    break; 
} 

      



Update

http://developer.android.com/reference/android/content/BroadcastReceiver.html

Action for network events in android sdk

0


source







All Articles