如何导入com.android.internal.telephony.ITelephony的Andr​​oid应用 [英] How to import com.android.internal.telephony.ITelephony to the Android application

查看:1093
本文介绍了如何导入com.android.internal.telephony.ITelephony的Andr​​oid应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要挂断来电我发现它,然后我希望把它挂起来。

的问题是这样的: com.android.internal.telephony.ITelephony 未得到解决。

我试图将包 com.android.internal.telephony 来我的应用程序并创建接口:

 包com.android.internal.telephony;

公共接口ITelephony {

    布尔结束呼叫();

    无效answerRingingCall();

    无效silenceRinger();

}
 

但呼叫没有结束

在这里,我发现电话,显示吐司(它显示),然后尝试挂断电话,但就像我说的第一个没有 com.android.internal.telephony.ITelephony 之前,我创建了一个包:

 私有类CallStateListener扩展PhoneStateListener {
        @覆盖
        公共无效onCallStateChanged(INT状态,串incomingNumber){
            开关(州){
            案例TelephonyManager.CALL_STATE_RINGING:
                //调用时,有人振铃这款手机
                Toast.makeText(CTX,来电:+ incomingNumber,Toast.LENGTH_LONG).show();
                 尝试{
                        TelephonyManager TM =(TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
                        C类=的Class.forName(tm.getClass()的getName());
                        方法米= c.getDeclaredMethod(getITelephony);
                        com.android.internal.telephony.ITelephony telephonyService =(com.android.internal.telephony.ITelephony)m.invoke(商标);

                        telephonyService =(com.android.internal.telephony.ITelephony)m.invoke(商标);
                        telephonyService.silenceRinger();
                        telephonyService.endCall();
                    }赶上(例外五){
                        e.printStackTrace();

                    }
                打破;
            }
        }
    }
 

我的清单和权限:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.a
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <用途-SDK
        安卓的minSdkVersion =17
        机器人:targetSdkVersion =17/>
    <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.PROCESS_OUTGOING_CALLS/>
    <使用-权限的Andr​​oid:名称=android.permission.CALL_PHONE/>
    <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名称=。MainActivity
            机器人:标签=@字符串/ APP_NAME>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>

                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
         <服务
            机器人:名称=。CallDetectService
            机器人:启用=真
            机器人:出口=假>
        < /服务>
    < /用途>



< /舱单>
 

解决方案

ITelephony 接口是内部的,所以你不能得到一个标准的参考吧。您的可以的使用反射所有的方式,即

  TelephonyManager TM =(TelephonyManager)getSystemService(TELEPHONY_SERVICE);

方法M1 = tm.getClass()getDeclaredMethod(getITelephony);
m1.setAccessible(真正的);
对象iTelephony = m1.invoke(商标);

方法平方米= iTelephony.getClass()getDeclaredMethod(silenceRinger);
方法立方米= iTelephony.getClass()getDeclaredMethod(结束呼叫)。

m2.invoke(iTelephony);
m3.invoke(iTelephony);
 

但无论哪种方式,这些方法所需要的 MODIFY_PHONE_STATE 权限,只能被授予系统的应用程序。所以,恐怕无论如何也不会正常工作。

I want to hang up incoming call I detect it and then I want to hang it up.

The problem is that this: com.android.internal.telephony.ITelephony is not resolved.

I tried to adding package com.android.internal.telephony to my application and create interface:

package com.android.internal.telephony;

public interface ITelephony {      

    boolean endCall();     

    void answerRingingCall();      

    void silenceRinger(); 

}

but the call is not ended.

Here I detect call, display toast(it is displayed) then try to hang up but as I said first there was no com.android.internal.telephony.ITelephony before I created that package:

private class CallStateListener extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                // called when someone is ringing to this phone
                Toast.makeText(ctx, "Incoming: " + incomingNumber, Toast.LENGTH_LONG).show();
                 try{
                        TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
                        Class c = Class.forName(tm.getClass().getName());
                        Method m = c.getDeclaredMethod("getITelephony");
                        com.android.internal.telephony.ITelephony telephonyService = (com.android.internal.telephony.ITelephony) m.invoke(tm);  

                        telephonyService = (com.android.internal.telephony.ITelephony) m.invoke(tm);
                        telephonyService.silenceRinger();
                        telephonyService.endCall();
                    }catch (Exception e) {
                        e.printStackTrace();

                    }
                break;
            }
        }
    }

My Manifest and permissions:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.a"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <service
            android:name=".CallDetectService"
            android:enabled="true"
            android:exported="false" >
        </service>
    </application>



</manifest>

解决方案

The ITelephony interface is internal, so you cannot get a standard reference to it. You could use reflection all the way, i.e.

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

Method m1 = tm.getClass().getDeclaredMethod("getITelephony");
m1.setAccessible(true);
Object iTelephony = m1.invoke(tm);

Method m2 = iTelephony.getClass().getDeclaredMethod("silenceRinger"); 
Method m3 = iTelephony.getClass().getDeclaredMethod("endCall"); 

m2.invoke(iTelephony);
m3.invoke(iTelephony);

But either way those methods need the MODIFY_PHONE_STATE permission, which can only be granted to system apps. So I'm afraid it won't work anyway.

这篇关于如何导入com.android.internal.telephony.ITelephony的Andr​​oid应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆