用android.telephony.PhongStateListener。文档里面有写:A listener class for monitoring changes in specific telephony states on the device, including service state, signal strength, message waiting indicator (voicemail), and others. Override the methods for the state that you wish to receive updates for, and pass your PhoneStateListener object, along with bitwise-or of the LISTEN_ flags to TelephonyManager.listen(). Note that access to some telephony information is permission-protected. Your application won't receive updates for protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the appropriate LISTEN_ flags.
1.自己实现一个ITelephony.aidl(源代码copy),eclipse会自动生成一个ITelephony.java ,这是我们就可以使用这个interface了。
2.获得ITelephony:TelephonyManager类中有一个私有方法 private Itelephony getITelephony() 可以获得ITelephony,但是如何使用这个私有方法有一个小技巧,要用到java 的 反射机制。简单的过程如下:
获得Class---》Method----》调用getITelephony.
PhoneStateListener fucklister = new PhoneStateListener ();
TelephonyManager temBoss = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
temBoss.listen(fucklister,PhoneStateListener.LISTEN_CALL_STATE);
2. 然后把从系统源码中把ITelephony.aidl文件拷贝到 com.android.internal.telephony包下。(也可以先新建一个ITelephony.aidl, 然后再把内容拷贝进去(ITelephony.aidl文件内容可以在http://www.netmite.com/android/mydroid/1.5/frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl,这个方法适合么有SDK源码文件的开发者));
3. 在src下新建一个包:android.telephony, 然后新建一个NeighboringCellInfo.aidl,其内容为:
package android.telephony;parcelable NeighboringCellInfo;4.从私有方法中获取ITelephony: 代码如下。tManager = (TelephonyManager)
this.getSystemService(Context.TELEPHONY_SERVICE);
//初始化iTelephony
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 {
iTelephony = (ITelephony) getITelephonyMethod.invoke(tManager, (Object[])null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}(其实android sdk里面的文档是很有帮助的, aidl建立方法不清楚的可以看 里面的文档, )
2. 然后从系统源码中把ITelephony.aidl文件拷贝到 com.android.internal.telephony包下。(也可以先新建一个ITelephony.aidl, 然后再把内容拷贝进去(ITelephony.aidl文件内容可以在http://www.netmite.com/android/mydroid/1.5/frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl 找到,这个方法适合没有SDK源码文件的开发者));
3. 在src下新建一个包:android.telephony, 然后新建一个NeighboringCellInfo.aidl,其内容为:
package android.telephony;parcelable NeighboringCellInfo;4.从私有方法中获取ITelephony: 代码如下。tManager = (TelephonyManager)
this.getSystemService(Context.TELEPHONY_SERVICE);
//初始化iTelephony
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 {
iTelephony = (ITelephony) getITelephonyMethod.invoke(tManager, (Object[])null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}(其实android sdk里面的文档是很有帮助的, aidl建立方法不清楚的可以看 里面的文档, )
请问下,这种aidl方式 是使用hide api的途径么?
应该算是一种使用隐藏API的途径吧!!
不过这样使用aidl不稳定吧。
万一哪天google把endcall删掉而不是隐藏 岂不不能用?
另外,楼主知不知道如何拦截短信呢?broadcast接收之后,应该怎样来cancle掉呢?
我的是在 sdk 1.5 的下面实现的,在其他更高的sdk上可不可以,我就不知道了!
[[email protected]][/email]
除了要有permission 之外,就是在需要用的地方初始化一下
我按照这个方法可以自动把来电挂断了,但是有个问题是有时候还会显示来电的界面,这样导致我的surface被destroy了,有没有办法让来电界面不显示出来啊?谢谢
其次个人感觉来电界面没有办法阻止,毕竟是系统级的,上层应用干涉不了