2017-04-17 26 views
1

특정 번호의 전화를 차단하고 싶습니다. 몇 가지 해결책을 시도했지만 오류가 발생했습니다. 이 솔루션을 사용해 보았지만 작동하지 않습니다. https://stackoverflow.com/a/9904826/1937692 이 제공기호 ITelephony를 해결할 수 없습니다

기호 ITelephony를 확인할 수 없습니다

프로젝트 구조 :

http://i.hizliresim.com/P02XOd.png

PhoneCallReceiver :

package com.example.myapplication; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.telephony.PhoneStateListener; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.widget.Toast; 
public class PhoneCallReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
     PhoneCallStateListener customPhoneListener = new PhoneCallStateListener(context); 
     telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); 


    }} 

ITelephony.aidl :

package com.android.internal.telephony; 

interface ITelephony { 

    boolean endCall(); 

    void answerRingingCall(); 

    void silenceRinger(); 
} 

PhoneCallStateListener :

package com.example.myapplication; 

import java.lang.reflect.Method; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.media.AudioManager; 
import android.os.Bundle; 
import android.preference.PreferenceManager; 
import android.telephony.PhoneStateListener; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.widget.Toast; 


import com.android.internal.telephony.ITelephony; //Error Line 

    public class PhoneCallStateListener extends PhoneStateListener { 

     private Context context; 
     public PhoneCallStateListener(Context context){ 
      this.context = context; 
     } 


     @Override 
     public void onCallStateChanged(int state, String incomingNumber) { 
      SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context); 

      switch (state) { 

       case TelephonyManager.CALL_STATE_RINGING: 

        String block_number = prefs.getString("block_number", null); 
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 
        //Turn ON the mute 
        audioManager.setStreamMute(AudioManager.STREAM_RING, true); 
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
        try { 
         Toast.makeText(context, "in"+block_number, Toast.LENGTH_LONG).show(); 
         Class clazz = Class.forName(telephonyManager.getClass().getName()); 
         Method method = clazz.getDeclaredMethod("getITelephony"); 
         method.setAccessible(true); 
         ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager); //Error Line 
         //Checking incoming call number 
         System.out.println("Call "+block_number); 

         if (incomingNumber.equalsIgnoreCase("+91"+block_number)) { 
          //telephonyService.silenceRinger();//Security exception problem 
          telephonyService = (ITelephony) method.invoke(telephonyManager); 
          telephonyService.silenceRinger(); 
          System.out.println(" in "+block_number); 
          telephonyService.endCall(); 
         } 
        } catch (Exception e) { 
         Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); 
        } 
        //Turn OFF the mute 
        audioManager.setStreamMute(AudioManager.STREAM_RING, false); 
        break; 
       case PhoneStateListener.LISTEN_CALL_STATE: 

      } 
      super.onCallStateChanged(state, incomingNumber); 
     }} 

오류 - 레드 라인 : http://i.hizliresim.com/YD8zQA.png

답변

1

인터페이스 ITelephony 패키지 보이지 패키지 com.android.internal.telephony 외부에서 그러므로 액세스 할 수 없습니다.

내부 안드로이드 API이기 때문입니다.