问题描述
我知道这个问题已经被问了很多遍了,但是没有答案,但是我仍然希望有人终于解决了这个问题.
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:
- 打个电话;
- 等待直到呼叫被应答;
- 在接听电话后(有超时)挂断电话;
与其他许多人一样,我也陷入了#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
(例如,):不起作用,其中未注册任何电话,因此事件不会触发. - 使用
com.android.internal.telephony.PhoneFactory
获得一个com.android.internal.telephony.Phone
实例(这是一切的关键):不起作用,工厂未初始化;尝试使用makeDefaultPhones
调用对其进行初始化会导致安全异常(例如此处)./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 likeregisterForPreciseCallStateChanged
(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 acom.android.internal.telephony.Phone
instance (which is the key to everything): does not work, the factory is not initialized; attempts to initialize it with amakeDefaultPhones
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 :)
推荐答案
如果您遵循
一步一步,就像:
- 使用平台证书对应用程序进行签名.这需要执行以下步骤:
- 将 android:sharedUserId ="android.uid.phone" 添加到apk清单的清单标签中.
- 在清单的应用程序标签中添加 android:process ="com.android.phone" .
- 您可能需要为清单添加一些额外的权限,并且还需要在项目的"Android Lint首选项"中更改 ProtectedPermission 的严重性.
- 从{Android Source}/build/target/product/security中获得platform.pk8 + platform.x509.pem(我已经在"> https://android.googlesource.com/platform/build/+/android-4.4.4_r1/target/product/security/)
- 从> https://github.com/getfatday/keytool-importkeypair 下载keytool-importkeypair
- 使用以下脚本通过以下命令获取平台的密钥库: keytool-importkeypair -k google_certificate.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform .我在cygwin上运行了该脚本,并对脚本进行了少量修改.
- 使用此密钥库对apk签名.
- 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 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上接听的去电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!