检测在Android上接听的去电 [英] Detecting outgoing call answered on Android

查看:63
本文介绍了检测在Android上接听的去电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问了很多遍了,但是没有答案,但是我仍然希望有人终于解决了这个问题.

I know this has been asked many times already, with no answers, but I still hope that someone has finally solved the problem.

问题:我有一个运行Android 2.3的非root用户设备.我需要创建一个服务,该服务:

The problem: I have a non-rooted device running Android 2.3. I need to create a service which:

  1. 打个电话;
  2. 等待直到呼叫被应答;
  3. 在接听电话后(有超时)挂断电话;

与其他许多人一样,我也陷入了#2的困境.以下是曾经建议的解决方案的摘要:

Like many others, I've got stuck with #2. Below is the summary of the solutions ever suggested:

  • 使用PhoneStateListener(最受欢迎):不起作用,对于拨出电话,它无法检测到我需要的东西.
  • 使用 com.android.internal.telephony.CallManager 及其方法,例如 registerForPreciseCallStateChanged (例如,此处)./li>
  • 检测传出的铃声(链接):作者-
  • Use PhoneStateListener (most popular): does not work, for an outgoing call it cannot detect what I need.
  • Use com.android.internal.telephony.CallManager and its methods like registerForPreciseCallStateChanged (e.g., this one): does not work, no phones are registered within it, so the events do not fire.
  • Use com.android.internal.telephony.PhoneFactory to obtain a com.android.internal.telephony.Phone instance (which is the key to everything): does not work, the factory is not initialized; attempts to initialize it with a makeDefaultPhones call result in a security exception (like here).
  • Detect the outgoing ringtone (link): the author - Dany Poplawec - states that detecting ringtones may help to solve the problem, but does not provide any details, so I was not able to try this technique.

看来一切都已经尝试过了,但是仍然有另外一个技巧可以救我:)

It looks like everything has been tried already, but there still may be one more trick that will save me :)

推荐答案

如果您遵循一步一步,就像:

  1. 使用平台证书对应用程序进行签名.这需要执行以下步骤:
  1. Signing the app with the platform certificate. This requires the following steps:
    • add android:sharedUserId="android.uid.phone" to the manifest-tag of your apk´s manifest.
    • add android:process="com.android.phone" to the application-tag of the manifest.
    • you may need to add a few extra permissions to your manifest, and will also need to change the severity for ProtectedPermission in the "Android Lint Preferences" of your project.
    • get the platform.pk8 + platform.x509.pem from {Android Source}/build/target/product/security (I have used the ones for 4.4.4r1 in https://android.googlesource.com/platform/build/+/android-4.4.4_r1/target/product/security/)
    • Download keytool-importkeypair from https://github.com/getfatday/keytool-importkeypair
    • Use this script to obtain the keystore for the platform with command: keytool-importkeypair -k google_certificate.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform . I ran it on cygwin, with a minor modification of the script.
    • Sign the apk using this keystore.

使用adb将应用程序安装为系统应用程序:

install the application as a system app using adb:

adb根

adb重新安装

adb push MyApp.apk/system/app

adb push MyApp.apk /system/app

adb shell chmod 644/systen/app/MyApp.apk

adb shell chmod 644 /systen/app/MyApp.apk

  • 重新启动设备.

  • Restart the device.

    我实际上已经在第二个项目符号中尝试了该解决方案,并且它对我也不起作用(在运行Kitkat的Galaxy S5上).第三个项目符号项目中的解决方案确实可以正常工作.无论包名称如何,该应用程序都以com.android.phone的身份运行,因此,如果要调试该应用程序,则需要附加到该进程.

    I have actually tried the solution in the 2nd bullet and it does not work for me either (on a Galaxy S5 running Kitkat). The solution in the 3rd bullet item does work quite OK. Regardless of the package name, the app runs as com.android.phone , so you need to attach to that process if you want to debug the app.

    这篇关于检测在Android上接听的去电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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