Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

roaming detection in android

Tags:

android

I'm trying to detect when the roaming activation occurs. So far I've used the following piece of code, but because I haven't been able to test it I am unaware of it's correctness

TelephonyManager telephonyManager = TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 

PhoneStateListener cellLocationListener = new PhoneStateListener() {
public void onCellLocationChanged(CellLocation location) {
  if(telephonyManager.isNetworkRoaming()
  {
    Toast.makeText(getApplicationContext(),"in roaming",Toast.LENGTH_LONG).show();
   }
 }
};

telephonyManager.listen(cellLocationListener, PhoneStateListener.LISTEN_CELL_LOCATION);

I've written this , thinking that in order for roaming to activate first the signal cell must change. Please let me know whether my deduction is correct or not, and if not how could I accomplish this.

like image 804
klaus johan Avatar asked Mar 03 '10 18:03

klaus johan


1 Answers

You can also test for isNetworkRoaming() in TelephonyManager if you want to know if there is Voice Roaming, even if the receiver is triggered by android.net.conn.CONNECTIVITY_CHANGE. I think this will also avoid the bug when the getActiveNetworkInfo() returns null.

public class RoamingListener extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        TelephonyManager telephony =
            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (telephony.isNetworkRoaming())
            Toast.makeText(context, "Is on TelephonyM Roaming", Toast.LENGTH_LONG).show();
    }
}
like image 189
Gabriel Avatar answered Oct 11 '22 13:10

Gabriel