How to solve this error "com.android.internal.telephony cannot be resolved for type" in android

I am creating a simple call filter application that restricts unwanted calls. I use the following code to restrict the call, but I can not fix the problem of this line in the lower code " com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke (tm); " it shows the error message com.android .internal.telephony cannot be allowed for a type in android, how to resolve this error.

public class CallBlockReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub } private void getTeleService(Context context) { TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); try { // Java reflection to gain access to TelephonyManager's // ITelephony getter Log.v("", "Get getTeleService..."); Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm); } catch (Exception e) { e.printStackTrace(); Log.e("", "FATAL ERROR: could not connect to telephony subsystem"); Log.e("", "Exception object: " + e); } } } 

Please help me.

+6
source share
3 answers

Have you added the ITelephony.AIDL file to the project? and if you added, then your package name should be com/android/internal/telephony/ITelephony.AIDL : for more information Blocking an incoming call . download the AIDL file from here

+10
source

You can use reflection methods to invoke the ITelephony object, thereby avoiding the need to specify a type and add an AIDL file. For example, ending a call:

 TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); Object telephonyService = m.invoke(tm); Class<?> telephonyServiceClass = Class.forName(telephonyService.getClass().getName()); Method endCallMethod = telephonyServiceClass.getDeclaredMethod("endCall"); endCallMethod.invoke(telephonyService); 
+5
source

You are using Android's internal / hidden API with reflection.

Make sure that you are trying to call a valid method name - there is a high probability that this API has changed or does not exist in the version you are developing.

0
source

Source: https://habr.com/ru/post/912200/


All Articles