ROAMING on Android, has anyone ever worked with it???

Put your problem here if it does not fit any of the other categories.

ROAMING on Android, has anyone ever worked with it???

Postby gumatias » Tue Mar 23, 2010 4:10 pm

Hello guys,

I'm working on a project that I need to know whether the device is on roaming or not. I've been digging until the very last page of Google without success, I haven't found any sample code of how to accomplish that.

This is the far that I could go:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 ServiceState ss = new ServiceState();
  2.  
  3.                 Log.i(TAG, "roaming 1: " + ss.getRoaming());
  4.  
  5.                 Log.i(TAG, "roaming 2: " + ss.getOperatorAlphaLong());
  6.  
  7.                 Log.i(TAG, "roaming 3: " + ss.getOperatorAlphaShort());
  8.  
  9.                 Log.i(TAG, "roaming 4: " + ss.getOperatorNumeric());
  10.  
  11.                 Log.i(TAG, "roaming 5: " + ss.getState());
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


and it results:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. roaming 1: false
  2.  
  3. roaming 2: null
  4.  
  5. roaming 3: null
  6.  
  7. roaming 4: null
  8.  
  9. roaming 5: 1
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



I have no idea what the snippet bellow is for, but I decided to add it into my Manifest file just in case:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.         <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  2.  
  3.         <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
  4.  
  5.         <uses-permission android:name="android.permission.READ_PHONE_STATE" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Can any of you guys help me on this one?

PS: I'm testing it on my Droid, and I've got plenty of SIM Cards from other countries and cities so that I can get the roaming status to be on.

Regards

-gustavo
gumatias
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Nov 30, 2009 4:17 pm

Top

Postby gumatias » Tue Mar 23, 2010 9:59 pm

Just figured that out! I realized that I was trying to work with the wrong classes... here is a sample code that I placed in my onCreate method to check the roaming status:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                
  2.  
  3. TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  4.  
  5.  
  6.  
  7. if(!tm.isNetworkRoaming()){
  8.  
  9.                         // roaming is off
  10.  
  11.                 } else if (tm.getSimCountryIso().equals(tm.getNetworkCountryIso())) {
  12.  
  13.                         // national roaming
  14.  
  15.                 } else {
  16.  
  17.                         // international roaming
  18.  
  19.                 }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


I'm not completely sure about this national and international roaming stuff, but I've tried with many kind of SIM cards and they all seemed to work perfectly!

Hope it'll help those that got into the same difficulty I did.

Cheers!
gumatias
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Nov 30, 2009 4:17 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests