Android弹出拨号界面和拨打电话实现
2012-11-03 11:28
465 查看
需要使用反射机制将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();
}
}
原文地址:http://www.blogjava.net/TiGERTiAN/archive/2011/01/25/343499.html
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();
}
}
原文地址:http://www.blogjava.net/TiGERTiAN/archive/2011/01/25/343499.html
相关文章推荐
- Android弹出拨号界面和拨打电话实现
- android实现拨打电话但不弹出拨号界面
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android调用拨号界面、拨打电话功能
- Android调用拨号界面、拨打电话功能
- Android 跳转到拨号界面/拨打电话/联系人
- cordova插件实现拨打电话(跳转到拨号界面或直接拨号)
- Android 实现电话拨号界面带按键声demo
- Android 调用系统的拨号服务实现 电话拨打功能
- WEB页面JS实现一键拨号的电话拨打功能
- Android中实现拨打电话和发送短信
- ios最佳项目内拨号拨打电话实现
- Android开发-动态添加与button响应(手机拨号界面的实现)
- Android使用Intent实现拨打电话的动作
- 实例解说android实现拨打电话的功能
- android实现拨打电话