运行 Oreo 中的拨出电话服务

Running a service on Outgoing Calls in Oreo

我正在开发一个应用程序,每当调用特定号码时都需要 运行 一些代码(打开 Activity)。 在 API 24 及更低版本中没问题,我在 Manifest 文件中注册了一个隐式接收器,并在扩展 BroadcastReceiver 的指定 class 中启动我的服务。但是在 API 26 中,您不能在接收器中注册 android.provider.Telephony.OUTGOING_CALL,因为它不起作用。

来自 Android 文档:

Note: If your app targets API level 26 or higher, you cannot use the manifest to declare a receiver for implicit broadcasts (broadcasts that do not target your app specifically), except for a few implicit broadcasts that are exempted from that restriction. In most cases, you can use scheduled jobs instead.

我在媒体上读过几篇类似这篇文章的文章 https://medium.com/@benexus/background-services-in-android-o-862121d96c95。有 JobSchedulerExplicit Receiver 等解决方案,但第一个用于更改网络状态,我找不到在 OUTGOING_CALL 事件和第二个事件上触发作业的方法在您的 activity 启动并且 运行ning.

之前有效

由于我的应用程序的性质,我需要监听去电,无论该应用程序是否 运行ning。如何在 API 26+ 中做到这一点?

请注意 https://developer.android.com/guide/components/broadcast-exceptions ACTION_NEW_OUTGOING_CALL 不受您提到的奥利奥限制。

如果您有尝试过但无法正常工作的代码,那么您应该post那个。