本来我已经差不多快可以自己做出来的啦~基本原理,文件都找到了~~但是~~还是差一点~不服啊~偶然看到一篇文章.很谢谢这位作者.其实这里主要就是用到aidl远程调用.只要学一下aidl其实一点也不难.但是我从网上根本找不到例子.除了这个~各位高手应该多写出来分享嘛~不废话了.大家看~
from:http://blog.chinaunix.net/u/9577/showart_1859341.html
Android-FireWall
一.Prepare ITelephony.aidl
Download iTelephony.aidl from http://code.google.com/p/mylockforandroid/source/browse/trunk/phone/src/com/android/internal/telephony/ITelephony.aidl?r=317
then add that file to src/com/android/internal/telephony/ of your project
二.Add permissions to AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
三.Write Code
import java.lang.reflect.Method;
import com.android.internal.telephony.ITelephony;
import android.telephony.*;
......
private TelephonyManager m_telephonyManager;
private ITelephony m_telephonyService;
private PhoneStateListener m_phoneStateListener;
private AudioManager m_audioManager;
....
m_telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
m_telephonyService = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
m_audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
m_telephonyManager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE);
....
class MyPhoneStateListener extends PhoneStateListener
{
public void onCallStateChanged(int state, String incomingNumber)
{
m_audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
m_audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//CALL_STATE_OFFHOOK;
break;
case TelephonyManager.CALL_STATE_RINGING:
// if incomingNumber need to be blocked ex:if num is "33",block it
// must be function "equals", no "=="
if ("33".equals(incomingNumber))
{
m_telephonyService.endCall();
}
else
{
m_audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
break;
default:
break;
}
}
}
}
from:http://blog.chinaunix.net/u/9577/showart_1859341.html
Android-FireWall
一.Prepare ITelephony.aidl
Download iTelephony.aidl from http://code.google.com/p/mylockforandroid/source/browse/trunk/phone/src/com/android/internal/telephony/ITelephony.aidl?r=317
then add that file to src/com/android/internal/telephony/ of your project
二.Add permissions to AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
三.Write Code
import java.lang.reflect.Method;
import com.android.internal.telephony.ITelephony;
import android.telephony.*;
......
private TelephonyManager m_telephonyManager;
private ITelephony m_telephonyService;
private PhoneStateListener m_phoneStateListener;
private AudioManager m_audioManager;
....
m_telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
m_telephonyService = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
m_audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
m_telephonyManager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE);
....
class MyPhoneStateListener extends PhoneStateListener
{
public void onCallStateChanged(int state, String incomingNumber)
{
m_audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
m_audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//CALL_STATE_OFFHOOK;
break;
case TelephonyManager.CALL_STATE_RINGING:
// if incomingNumber need to be blocked ex:if num is "33",block it
// must be function "equals", no "=="
if ("33".equals(incomingNumber))
{
m_telephonyService.endCall();
}
else
{
m_audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
break;
default:
break;
}
}
}
}