如何在android中解决此错误"com.android.internal.telephony无法解析为类型"

Pra*_*dam 6 methods android telephony class telephonymanager

我正在创建简单的呼叫过滤应用程序,限制不必要的呼 我使用以下代码来限制调用,但我无法在下面的代码中解决此行的问题" com.android.internal.telephony.ITelephony telephonyService =(ITelephony)m.invoke(tm); "它显示错误消息com. android.internal.telephony无法解析为android中的某个类型如何解决此错误.

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);
        }
}

}
Run Code Online (Sandbox Code Playgroud)

请帮我 .

ρяσ*_*я K 10

ITelephony.AIDL在项目中添加了文件?如果您已添加,那么您的包名必须是com/android/internal/telephony/ITelephony.AIDL:有关更多信息阻止来电.从这里下载AIDL文件


小智 7

您可以使用反射来调用ITelephony对象上的方法,从而避免指定类型并添加AIDL文件.例如,结束通话:

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);
Run Code Online (Sandbox Code Playgroud)