Well, I have found solution - very odd but it's working.
Basically method tries to get telephony service if it's null - it returns false, if it's not null (e.g. for HTC Flyer TelephonyManager
is not null) method tries to run PackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
using reflection, since this method is not available for old versions of SDK.
Here is a code:
private Boolean hasTelephony;
public boolean hasTelephony()
{
if(hasTelephony==null)
{
TelephonyManager tm=(TelephonyManager )this.getSystemService(Context.TELEPHONY_SERVICE);
if(tm==null)
{
hasTelephony=new Boolean(false);
return hasTelephony.booleanValue();
}
if(this.getSDKVersion() < 5)
{
hasTelephony=new Boolean(true);
return hasTelephony;
}
PackageManager pm = this.getPackageManager();
Method method=null;
if(pm==null)
return hasCamera=new Boolean(false);
else
{
try
{
Class[] parameters=new Class[1];
parameters[0]=String.class;
method=pm.getClass().getMethod("hasSystemFeature", parameters);
Object[] parm=new Object[1];
parm[0]=new String(PackageManager.FEATURE_TELEPHONY);
Object retValue=method.invoke(pm, parm);
if(retValue instanceof Boolean)
hasTelephony=new Boolean(((Boolean )retValue).booleanValue());
else
hasTelephony=new Boolean(false);
}
catch(Exception e)
{
hasTelephony=new Boolean(false);
}
}
}
return hasTelephony;
}
More or less the same approach is workable for checking of camera availability
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…