Search code examples
androidtelephonymanager

TelephonyManager get the operator name error


I have got Button OnClick ether redirect to another activity or open dialog popup. when i click on button always dialog open unless operator name are not contains non of those string.

did i made mistake somewhere or contains dose not works?

  TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    //get the operator name
    final String operatorName = telephonyManager.getNetworkOperatorName(); 
    // Getting connected network iso country code

    Log.d("ON", "Operator name = " + operatorName);


    final Button startBtn = (Button) findViewById(R.id.sms);
    startBtn.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View arg0) {

            // TODO Auto-generated method stub

            if(operatorName.contains("iffgaff") || operatorName.contains("Giff") || operatorName.contains("GIFF")
                    || operatorName.contains("giff") || operatorName.contains("Gaff") || operatorName.contains("gaff")
                    || operatorName.contains("GAFF")){

                Intent intent = new Intent(RegisterActivity.this,
                        LiteActivity.class);
                startActivity(intent);

            } else {

            showDialog(CUSTOM_DIALOG_ID);
            }
        }

    });

I will appreciate your help...


Solution

  • Do You want that this option will be active if the operatorName contains one of the strings or all? If You want to know if only one of these strings are contained, use one logical operator |, so every value will be checked and true will be returned, if one of the strings are contained.