本文介绍了如何阻止电话是登录Android上的通话记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写阻止某些电话的应用程序。我使用的广播接收器收听来电:

I'm writing an application that block some phone calls. I use a broadcast receiver to listen to incoming calls:

<receiver android:name="InComingCallReceiver">
<intent-filter android:priority="100">
    <action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>

和我取消了电话,我不想要的:

And I cancelled the calls I don't want:

TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);    
try {   
    Class c = Class.forName(telephony.getClass().getName());   
    Method m = c.getDeclaredMethod("getITelephony");   
    m.setAccessible(true);   
    telephonyService = (ITelephony) m.invoke(telephony);   
    telephonyService.silenceRinger();   
    telephonyService.endCall();  
} 
catch (Exception e) {   
    Log.e(LOG_TAG,"Exception in InComingCallReceiver.onReceive");
    Log.e(LOG_TAG,"ERROR: " + e.toString() + " Message: " + e.getMessage() + " --- " + e.getLocalizedMessage() + " Cause: " + e.getCause() + " StackTrace: " + e.getStackTrace());
}

该呼叫indead取消,但它出现在呼叫记录。

The call is indead cancelled but it appears in the call log.

有没有办法来prevent正在通话记录中的通话记录后,我取消了呢?

Is there a way to prevent call being log in the call log after I cancelled it?

如果没有,我怎样才能从日志中删除编程?

If not, how can I delete from the log programatically?

推荐答案

它看起来像有没有办法prevent系统记录在呼叫记录中的电话。
因此,我们必须从通话记录删除。
问题是,该条目在通话记录长后,电话已经挂断加入,我们没有看到它在数据库中,当我们在广播接收器的方法的onReceive

It Look like there is no way to prevent the system to log the phone call in the call log.So we have to delete it from the call log.The problem is that the entry is added in the call log long after the phone call has been hang up and we do not see it in the database when we are in the onReceive method of the broadcast receiver.

经过大量的研究和测试,我想出了这个简单的解决方案。我做2秒线程睡眠befor删除。

After a lot of research and tests, I came up with this simple solution. I make the thread sleep for 2 seconds befor deleting it.

这里的code:

@Override
public void onReceive(Context context, Intent intent) {
    Log.i(LOG_TAG, "Début InComingCallReceiver.onReceive");
    Log.i(LOG_TAG, "IS ORDERED = " + this.isOrderedBroadcast());

    Bundle extras = intent.getExtras();
    if (extras != null) {

        String state = extras.getString(TelephonyManager.EXTRA_STATE);
        Log.i(LOG_TAG, state);

        String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
        Log.i(LOG_TAG, phoneNumber);

        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {

            if (phoneNumber.contains(PHONE_FILTER)) {

                Log.i(LOG_TAG, "Cancelling the incoming call");

                TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);    
                try {   
                    Class c = Class.forName(telephony.getClass().getName());   
                    Method m = c.getDeclaredMethod("getITelephony");   
                    m.setAccessible(true);   
                    telephonyService = (ITelephony) m.invoke(telephony);   
                    telephonyService.silenceRinger();   
                    telephonyService.endCall();  

                } 
                catch (Exception e) {   
                    Log.e(LOG_TAG,"Exception in InComingCallReceiver.onReceive");
                    Log.e(LOG_TAG,"ERROR: " + e.toString() + " Message: " + e.getMessage() + " --- " + e.getLocalizedMessage() + " Cause: " + e.getCause() + " StackTrace: " + e.getStackTrace());
                }
            }
        }
        else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
            if (phoneNumber.contains(PHONE_FILTER)) {

                Log.i(LOG_TAG, "Waiting 2sec");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Log.i(LOG_TAG, "After Waiting 2sec");


                Log.i(LOG_TAG, "Deleting the incoming call from call log");
                int nbRowDeleted = context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER + " = ?", new String[] {phoneNumber});
                Log.i(LOG_TAG, nbRowDeleted + " Row(s) Deleted");
            }
        }
    }
}

这篇关于如何阻止电话是登录Android上的通话记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 19:46