Android弹出拨号界面和拨打电话实现
2014-12-28 21:58
330 查看
需要使用反射机制将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();
}
}
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();
}
}
相关文章推荐
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- android实现拨打电话但不弹出拨号界面
- Android弹出拨号界面和拨打电话实现
- Android调用拨号界面、拨打电话功能
- Android 调用系统的拨号服务实现 电话拨打功能
- cordova插件实现拨打电话(跳转到拨号界面或直接拨号)
- Android调用拨号界面、拨打电话功能
- Android 实现电话拨号界面带按键声demo
- Android 跳转到拨号界面/拨打电话/联系人
- Android实战—实现自动读取通讯录和通话记录切换,ViewPage滑屏效果,可拨打电话
- android中拨打电话的几种实现
- android电话拨打的实现
- android实现拨打电话
- Android中实现拨打电话和发送短信
- android实现拨打电话
- android应用开发全程实录-实现甩动拨打和挂断电话