Calling this method in my Receiver class that extend BroadcastReceiver to cancel incoming call.There is no error in code at compile time but when this method is called the exception is thrown that is.
Exception
java.lang exception android.content.context.getsystemservice(java.lang.string)' on a null object reference
Code
private void disconnectPhoneItelephony(Context context)
{
ITelephony telephonyService;
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
try
{
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.endCall();
}
catch (Exception e)
{
e.printStackTrace();
}
}