3

with connectivitymanager and broadcast receiver I'm able to get connection and disconnection events as explained Eric's post here

What I would like to know is the change in type while network is being connected. Ex: 3G to H+ and vice versa.. I see there are no events inside OnReceive(..) when this change happens...

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

expected output: expect an event in BCR when there is change from 3G to h+ or Edge...

Community
  • 1
  • 1
user12295
  • 211
  • 1
  • 3
  • 4

1 Answers1

0

Here, on switch statement you can do certain taks. A Thread can call the following code and keep an eye on 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

Intent action for network events in android sdk

Community
  • 1
  • 1
Mayank
  • 8,777
  • 4
  • 35
  • 60
  • I know this event handling method. but how/where to register such events. Although this is used with Telephonymanager, doesnt give more details of connected or disconnected events as described in the erics post said above. – user12295 Mar 14 '12 at 14:01
  • well you can write your own custom class that extends TelephonyManager and then implement certain function that constatly checking if previous connection state is still vaild or not, if not then notify. – Mayank Mar 14 '12 at 14:06
  • Constant polling also no big help as the switching is very transient sometimes.. I'm looking for something more generic system event. – user12295 Mar 14 '12 at 14:12
  • Have you found an answer for that problem? (without the need of polling) – denis Nov 21 '12 at 07:21