The reflection mechanism needs to be used to reflect itelephony.
Private void dial (string number ){
Class <telephonymanager> C = telephonymanager. Class;
Method getitelephonymethod = NULL;
Try {
Getitelephonymethod = C. getdeclaredmethod ("getitelephony ",
(Class []) null );
Getitelephonymethod. setaccessible (true );
} Catch (securityexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (nosuchmethodexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Try {
Telephonymanager tmanager = (telephonymanager) getsystemservice (context. telephony_service );
Object itelephony;
Itelephony = (object) getitelephonymethod. Invoke (tmanager, (object []) null );
Method dial = itelephony. getclass (). getdeclaredmethod ("dial", String. Class );
Dial. Invoke (itelephony, number );
} Catch (illegalargumentexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (illegalaccessexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (securityexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (nosuchmethodexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (invocationtargetexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Private void call (string number ){
Class <telephonymanager> C = telephonymanager. Class;
Method getitelephonymethod = NULL;
Try {
Getitelephonymethod = C. getdeclaredmethod ("getitelephony ",
(Class []) null );
Getitelephonymethod. setaccessible (true );
} Catch (securityexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (nosuchmethodexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Try {
Telephonymanager tmanager = (telephonymanager) getsystemservice (context. telephony_service );
Object itelephony;
Itelephony = (object) getitelephonymethod. Invoke (tmanager, (object []) null );
Method dial = itelephony. getclass (). getdeclaredmethod ("call", String. Class );
Dial. Invoke (itelephony, number );
} Catch (illegalargumentexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (illegalaccessexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (securityexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (nosuchmethodexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (invocationtargetexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}