Search code examples
androidtelephonymanager

Chances of TELEPHONY_SERVICE return null


Is there any chances of getting TELEPHONY_SERVICE as null ?

     TelephonyManager teleman = (TelephonyManager) getBaseContext()
            .getSystemService(Context.TELEPHONY_SERVICE);

I mean is there any chances of getting teleman as null in the above line ?

Thanks in advance for reply.


Solution

  • Yes, it can. As getSystemService()'s manual says:

    Returns

    The service or null if the name does not exist.

    For some basic services it is quite unlikely, however telephony is not one of those. Do not expect it on i.e. GoogleTV or some sort of tablets. You can check if certain feature is avaiable by using hasSystemFeature()