简体   繁体   English

无法通过ITelephony在我的Android系统应用程序中自动接听电话

[英]Can't auto answer phone call within my Android System App via ITelephony

I would like to make use of android.permission.MODIFY_PHONE_STATE on Android Lollipop by auto-answering a call, much like some of the hands-free "driver assist" apps that are available on the Play Store. 我想通过自动接听电话来利用Android Lollipop上的android.permission.MODIFY_PHONE_STATE,就像Play商店中提供的一些免提“驾驶员辅助”应用程序一样。

I found some code from the AutoAnswer project , but when I run it, I get a InvocationTargetException stating that "neither the user #### nor the application has MODIFY_PHONE_STATE permissions." 我从AutoAnswer项目中找到了一些代码,但是当我运行它时,我收到一个InvocationTargetException,指出“用户####或应用程序都没有MODIFY_PHONE_STATE权限。”

However, in my Manifest I have: <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> and I have installed my apk into /system/app/AutoAnswer.apk and set it's permissions to 644. 但是,在清单中,我有: <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> ,我已经将我的apk安装到/system/app/AutoAnswer.apk ,并将其权限设置为644。

The requirement is that I don't need a phone to be rooted in order for it to work, but I do have the ability to add my application to the custom ROM (so it is a system app). 要求是我不需要植根电话即可工作,但是我确实能够将应用程序添加到自定义ROM(因此它是系统应用程序)。

The calling code looks like this: 调用代码如下所示:

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

        Method m1 = telephonyService.getClass().getMethod("silenceRinger");
        Method m2 = telephonyService.getClass().getMethod("answerRingingCall");

        //m1.invoke(telephonyService); // not supported for OnePlus2
        m2.invoke(telephonyService); // <- This is the line that throws the error

Why is it not allowing me to use MODIFY_PHONE_STATE from my system app..? 为什么不允许我从系统应用程序使用MODIFY_PHONE_STATE? Is there a workaround? 有解决方法吗?

For a work around you may wish to check out How can incoming calls be answered programmatically in Android 5.0 (Lollipop)? 要解决此问题,您不妨查看一下如何在Android 5.0(Lollipop)中以编程方式接听来电?

If getting explicit grant of Notification access from the user is ok then you can check out my answer there which worked for me under Android 5.0 and 5.1. 如果可以从用户那里获得显式授予的通知访问权限,那么您可以在那里查看我的答案,该答案在Android 5.0和5.1下对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 鉴于我检测到电话正在通过我的应用程序响铃,如何自动接听和来电 - how to auto answer and incoming call given i have detected that the phone is ringing via my app 未经CALL_PHONE许可,如何通过ITelephony界面拒绝来电? - How can I reject incoming calls via the ITelephony interface without the CALL_PHONE permission? 无法在我的手机上将 android package 设置为系统应用程序 - Can't set android package as system app on my phone 如何终止ITelephony内的来电 - How to terminate an incoming call within ITelephony 如何通过我的android应用拨打电话号码? - How can I call a phone number through my android app? 无法在Android手机上运行我的应用 - Can't Run My App on My Android Phone android.permission.ANSWER_PHONE_CALLS 如何使用? 用于自动应答 - android.permission.ANSWER_PHONE_CALLS How I can use? for auto answer 无法在我的Android 2.3.6手机上安装Titanium的应用程序 - Can't install Titanium's app on my android 2.3.6 phone 我无法在我的 Android 计算器中得到正确的答案 - I can't get the answer proper answer in my Android Calculator 在我的Android应用程序的背景中打电话 - Phone call in background of my android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM