how to resolve this error “com.android.internal.te

2019-01-11 12:11发布

i am creating simple call filter application which restrict unwanted calls. i use following code to restrict call but i am unable to resole problem of this line in below code " com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm); " it show the error message com.android.internal.telephony cannot be resolved to 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 .

3条回答
Lonely孤独者°
2楼-- · 2019-01-11 12:16

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

Check that you're trying to invoke a valid method name - there's a great chance that this API has changed or does not exists in the version you're developing for.

查看更多
太酷不给撩
3楼-- · 2019-01-11 12:21

You can use reflection to call methods on the ITelephony object thus avoiding the need to specify the type and add the AIDL file. For instance, 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);
查看更多
【Aperson】
4楼-- · 2019-01-11 12:37

you have added ITelephony.AIDL file in your project? and if you have added then your package name must be com/android/internal/telephony/ITelephony.AIDL: for more information Blocking Incoming call. download AIDL file from here

查看更多
登录 后发表回答