Android 通过Java反射 拨打、挂断电话
2021/7/10 17:06:09
本文主要是介绍Android 通过Java反射 拨打、挂断电话,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public void call(String number) { Class<TelephonyManager> c = TelephonyManager.class; Method getITelephonyMethod = null; try { getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null); getITelephonyMethod.setAccessible(true); TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Object iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null); Method call = iTelephony.getClass().getDeclaredMethod("call", String.class); call.invoke(iTelephony, number); }catch (Exception e){ e.printStackTrace(); } } public void endCall() { Class<TelephonyManager> c = TelephonyManager.class; Method getITelephonyMethod = null; try { getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null); getITelephonyMethod.setAccessible(true); TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Object iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null); Method endCall = iTelephony.getClass().getDeclaredMethod("endCall"); endCall.invoke(iTelephony); }catch (Exception e){ e.printStackTrace(); } }
<uses-permission android:name="android.permission.CALL_PHONE"/><!-- 拨打电话的权限 -->
这篇关于Android 通过Java反射 拨打、挂断电话的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-19环境变量处理课程:新手入门教程
- 2024-09-19接口模块封装课程:新手入门指南
- 2024-09-19请求动作封装课程:新手入门教程
- 2024-09-19拖拽表格课程:新手入门指南
- 2024-09-19页面权限课程:新手必学的权限管理入门教程
- 2024-09-19如何正确主动登出课程:新手必读教程
- 2024-09-19Element-Plus课程:新手入门与初级教程
- 2024-09-19Token处理入门教程:新手必看指南
- 2024-09-19如何应对被动登出课程的情况:新手必读指南
- 2024-09-19打包优化课程:初学者的必备指南