我的 Manifest.xml:</p>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
我可以捕获所有收入电话号码并将其保存在我的数据库中。但在某些手机中,函数 endCall() 不起作用。钟声依旧响起。我怎么解决这个问题?谢谢。
public class CallReceiver extends BroadcastReceiver {
public static final String TEST_NUMBER = "62419770";
private static final String ACTION = "android.intent.action.PHONE_STATE";
private ITelephony iTelephony;
private AudioManager mAudioManager;
public void onReceive(Context context, Intent intent) {
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
TelephonyManager telephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Method getITelephonyMethod = TelephonyManager.class.getDeclaredMethod("getITelephony", (Class[]) null);
getITelephonyMethod.setAccessible(true);
iTelephony = (ITelephony) getITelephonyMethod.invoke(telephonyMgr,(Object[]) null);
}
catch (Exception e) {
e.printStackTrace();
}
String action = intent.getAction();
if (ACTION.equals(action)) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) {
if(NameListData.hasCallName(number,DataBase.NameRecord.TYPE_BLACK))
{
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
try {
iTelephony.endCall();
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
NotificationUtils.showSingleNotification(context,
context.getString(R.string.notification_intercept_phone_title),
number, InterceptListActivity.class,NotificationUtils.mInterceptrCallNotificationId);
HarassCallUtils.addHarassCall(context, new CallItem(0, number, new Date().getTime(), 0 ,false));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}