InCallService 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
此服务由希望提供用于管理电话呼叫的功能的应用实现。
[Android.Runtime.Register("android/telecom/InCallService", ApiSince=23, DoNotGenerateAcw=true)]
public abstract class InCallService : Android.App.Service
[<Android.Runtime.Register("android/telecom/InCallService", ApiSince=23, DoNotGenerateAcw=true)>]
type InCallService = class
inherit Service
- 继承
- 属性
注解
此服务由希望提供用于管理电话呼叫的功能的应用实现。 <h2>成为默认电话应用</h2> 默认拨号程序/电话应用是一个,提供呼叫内用户界面,而设备处于呼叫状态。 它还为用户提供了一种启动呼叫的方法,并查看其设备上的呼叫历史记录。 设备与系统提供的默认拨号程序/手机应用捆绑在一起。 用户可以从系统应用中选择要接管此角色的单个应用。 希望实现此角色的应用使用 android.app.role.RoleManager
请求他们填写 android.app.role.RoleManager#ROLE_DIALER
角色。
默认手机应用在设备处于呼叫状态时提供用户界面,并且设备不在汽车模式下(即 UiModeManager#getCurrentModeType()
不是 android.content.res.Configuration#UI_MODE_TYPE_CAR
)。
为了填补角色 android.app.role.RoleManager#ROLE_DIALER
,应用必须满足许多要求: <ul><li>它必须处理 Intent#ACTION_DIAL
意向。 这意味着应用必须为用户提供拨号盘 UI 才能启动传出呼叫。</li><li>它必须完全实现 InCallService
API 并提供传入调用 UI 以及正在进行的调用 UI。</li></ul>
注意:如果填充绑定期间返回android.app.role.RoleManager#ROLE_DIALER
null
InCallService
的应用,电信框架将自动回退到使用设备上预加载的拨号程序应用。 系统将向用户显示通知,让他们知道其呼叫是继续使用预加载拨号程序应用。 应用不应返回 null
绑定;这样做意味着它不满足其要求 android.app.role.RoleManager#ROLE_DIALER
。
注意:如果你的应用在运行时填充 android.app.role.RoleManager#ROLE_DIALER
并进行更改,导致它不再满足此角色的要求, android.app.role.RoleManager
将自动从角色中删除你的应用并关闭你的应用。 例如,如果你用于 android.content.pm.PackageManager#setComponentEnabledSetting(ComponentName, int, int)
以编程方式禁用 InCallService
应用在其清单中声明,你的应用将不再满足预期的 android.app.role.RoleManager#ROLE_DIALER
要求。
当用户拨打紧急呼叫时,将始终使用预加载拨号程序,即使你的应用填补了 android.app.role.RoleManager#ROLE_DIALER
角色。 为了确保在拨打紧急呼叫时获得最佳体验,默认拨号程序应始终用于 android.telecom.TelecomManager#placeCall(Uri, Bundle)
拨打呼叫(包括紧急呼叫)。 这可确保平台能够验证请求是否来自默认拨号程序。 如果非预加载拨号程序应用用于 Intent#ACTION_CALL
拨打紧急呼叫,则会将其提升到预加载拨号程序应用,用于 Intent#ACTION_DIAL
确认;这是一种不理想的用户体验。
下面是一个示例清单注册。InCallService
元数据 TelecomManager#METADATA_IN_CALL_SERVICE_UI
表示此特定 InCallService
实现打算替换内置调用 UI。 元数据 TelecomManager#METADATA_IN_CALL_SERVICE_RINGING
表示将 InCallService
播放传入呼叫的铃声。 有关在应用中显示传入呼叫 UI 和播放铃声的详细信息,请参阅下文。
{@code
<service android:name="your.package.YourInCallServiceImplementation"
android:permission="android.permission.BIND_INCALL_SERVICE"
android:exported="true">
<meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
<meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
android:value="true" />
<intent-filter>
<action android:name="android.telecom.InCallService"/>
</intent-filter>
</service>
}
<em>注意:不应使用属性android:exported="false"
标记;InCallService
这样做可能会导致在调用期间绑定到实现失败。</em>
除了实现 InCallService
API 之外,还必须在清单中声明处理意向的活动 Intent#ACTION_DIAL
。 下面的示例演示了如何完成此操作:
{@code
<activity android:name="your.package.YourDialerActivity"
android:label="@string/yourDialerActivityLabel">
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
}
当用户安装应用程序并首次运行应用程序时,应使用 android.app.role.RoleManager
提示用户查看他们是否希望你的应用成为新的默认手机应用。 <p id=“requestRole”> 下面的代码显示你的应用如何请求成为默认电话/拨号程序应用:
{@code
private static final int REQUEST_ID = 1;
public void requestRole() {
RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
startActivityForResult(intent, REQUEST_ID);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_ID) {
if (resultCode == android.app.Activity.RESULT_OK) {
// Your app is now the default dialer app
} else {
// Your app is not the default dialer app
}
}
}
}
<p id=“companionInCallService”><h3>Access to InCallService for可穿戴设备</h3><ol> 如果你的应用是第三方配套应用,并且想要访问 InCallService API,则应用可以执行的操作:
<ol><li> Declare MANAGE_ONGOING_CALLS permission in your manifest <li> Associate with a physical可穿戴设备 via the android.companion.CompanionDeviceManager
API as a companion app. 请参阅: https://developer.android.com/guide/topics/connectivity/companion-device-pairing<li> 通过 BIND_INCALL_SERVICE 权限 </ol/ol>< 实现此 InCallService>
</pre><p id=“incomingCallNotification”><h3 显示传入呼叫通知</h3>> 当应用收到新的传入呼叫时InCallService#onCallAdded(Call)
,它负责显示传入呼叫的传入呼叫 UI。 它应使用 android.app.NotificationManager
API 发布新的传入呼叫通知来执行此操作。
应用声明元数据 TelecomManager#METADATA_IN_CALL_SERVICE_RINGING
的位置,它负责播放传入呼叫的铃声。 你的应用应创建一个 android.app.NotificationChannel
指定所需铃声的命令。 例如:
<code>
NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
NotificationManager.IMPORTANCE_MAX);
// other channel setup stuff goes here.
// We'll use the default system ringtone for our incoming call notification channel. You can
// use your own audio resource here.
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
channel.setSound(ringtoneUri, new AudioAttributes.Builder()
// Setting the AudioAttributes is important as it identifies the purpose of your
// notification sound.
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build());
NotificationManager mgr = getSystemService(NotificationManager.class);
mgr.createNotificationChannel(channel);
</code>
当应用收到新的传入呼叫时,它会为传入呼叫创建一个 android.app.Notification
,并将其与传入呼叫通知通道相关联。 可以在通知上指定一个 android.app.PendingIntent
通知,该通知将启动全屏传入呼叫 UI。 如果用户主动使用手机,通知管理器框架会将通知显示为头通知。 当用户不使用手机时,将改用全屏传入呼叫 UI。 例如:
<code>{@code
// Create an intent which triggers your fullscreen incoming call user interface.
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, YourIncomingCallActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
// Build the notification as an ongoing high priority item; this ensures it will show as
// a heads up notification which slides down over top of the current content.
final Notification.Builder builder = new Notification.Builder(context);
builder.setOngoing(true);
builder.setPriority(Notification.PRIORITY_HIGH);
// Set notification content intent to take user to the fullscreen UI if user taps on the
// notification body.
builder.setContentIntent(pendingIntent);
// Set full screen intent to trigger display of the fullscreen UI when the notification
// manager deems it appropriate.
builder.setFullScreenIntent(pendingIntent, true);
// Setup notification content.
builder.setSmallIcon( yourIconResourceId );
builder.setContentTitle("Your notification title");
builder.setContentText("Your notification content.");
// Use builder.addAction(..) to add buttons to answer or reject the call.
NotificationManager notificationManager = mContext.getSystemService(
NotificationManager.class);
notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, builder.build());
}
适用于 . 的 android.telecom.InCallService
Java 文档
本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。
构造函数
InCallService() |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 |
InCallService(IntPtr, JniHandleOwnership) |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 |
字段
AccessibilityService |
|
AccountService |
|
ActivityService |
|
AlarmService |
|
AppOpsService |
用于 |
AppSearchService |
|
AppwidgetService |
|
AudioService |
用于 |
BatteryService |
|
BindAllowActivityStarts |
已过时.
|
BindExternalServiceLong |
的工作方式与 |
BindNotPerceptible |
已过时.
|
BindSharedIsolatedProcess |
已过时.
标志: |
BiometricService |
|
BlobStoreService |
|
BluetoothService |
|
BugreportService |
用于捕获 bug 报告的服务。 (继承自 Context) |
CameraService |
|
CaptioningService |
用于 |
CarrierConfigService |
用于 |
ClipboardService |
|
CompanionDeviceService |
|
ConnectivityDiagnosticsService |
用于 |
ConnectivityService |
用于 |
ConsumerIrService |
用于 |
CredentialService |
|
CrossProfileAppsService |
用于 |
DeviceIdDefault |
默认设备 ID,即主设备(非虚拟)设备的 ID。 (继承自 Context) |
DeviceIdInvalid |
设备 ID 无效。 (继承自 Context) |
DeviceLockService |
|
DevicePolicyService |
|
DisplayHashService |
|
DisplayService |
|
DomainVerificationService |
|
DownloadService |
与 |
DropboxService |
|
EuiccService |
|
FileIntegrityService |
|
FingerprintService |
用于 |
GameService |
|
GrammaticalInflectionService |
|
HardwarePropertiesService |
用于 |
HealthconnectService |
|
InputMethodService |
用于 |
InputService |
|
IpsecService |
|
JobSchedulerService |
|
KeyguardService |
|
LauncherAppsService |
用于 |
LayoutInflaterService |
用于 |
LocaleService |
|
LocationService |
与 |
MediaCommunicationService |
|
MediaMetricsService |
用于 |
MediaProjectionService |
用于 |
MediaRouterService |
|
MediaSessionService |
用于 |
MidiService |
用于 |
NetworkStatsService |
用于 |
NfcService |
|
NotificationService |
与 |
NsdService |
用于 |
OverlayService |
|
PeopleService |
|
PerformanceHintService |
|
PowerService |
|
PrintService |
|
ReceiverExported |
已过时.
|
ReceiverNotExported |
已过时.
|
ReceiverVisibleToInstantApps |
已过时.
标志: |
RestrictionsService |
用于 |
RoleService |
用于 |
SearchService |
|
SensorService |
|
ServiceInterface |
必须 |
ShortcutService |
|
StatusBarService |
|
StopForegroundDetach |
已过时.
选择器: |
StopForegroundLegacy |
选择器: |
StopForegroundRemove |
已过时.
选择器: |
StorageService |
用于 |
StorageStatsService |
|
SystemHealthService |
|
TelecomService |
|
TelephonyImsService |
|
TelephonyService |
用于 |
TelephonySubscriptionService |
用于 |
TextClassificationService |
|
TextServicesManagerService |
用于 |
TvInputService |
|
TvInteractiveAppService |
|
UiModeService |
用于 |
UsageStatsService |
|
UsbService |
用于 |
UserService |
用于 |
VibratorManagerService |
用于 |
VibratorService |
用于 |
VirtualDeviceService |
用于 |
VpnManagementService |
|
WallpaperService |
用于 |
WifiAwareService |
用于 |
WifiP2pService |
用于 |
WifiRttRangingService |
与 |
WifiService |
用于 |
WindowService |
|
属性
Application |
返回拥有此服务的应用程序。 (继承自 Service) |
ApplicationContext |
返回当前进程的单个全局 Application 对象的上下文。 (继承自 ContextWrapper) |
ApplicationInfo |
返回此上下文包的完整应用程序信息。 (继承自 ContextWrapper) |
Assets |
返回应用程序的包的 AssetManager 实例。 (继承自 ContextWrapper) |
AttributionSource |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Context) |
AttributionTag |
属性可用于复杂应用中,以逻辑方式分隔应用的各个部分。 (继承自 Context) |
BaseContext | (继承自 ContextWrapper) |
CacheDir |
返回文件系统上特定于应用程序的缓存目录的绝对路径。 (继承自 ContextWrapper) |
CallAudioState |
获取当前电话呼叫音频状态。 |
Calls |
获取此调用服务要显示的当前 s 列表 |
Class |
返回此 |
ClassLoader |
返回可用于检索此包中的类的类加载程序。 (继承自 ContextWrapper) |
CodeCacheDir |
返回文件系统上用于存储缓存代码的应用程序特定缓存目录的绝对路径。 (继承自 ContextWrapper) |
ContentResolver |
返回应用程序的包的 ContentResolver 实例。 (继承自 ContextWrapper) |
CurrentCallEndpoint |
获取当前的 CallEndpoint。 |
DataDir |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 ContextWrapper) |
DeviceId |
获取与此上下文关联的设备 ID。 (继承自 Context) |
Display |
获取与此上下文关联的显示。 (继承自 Context) |
ExternalCacheDir |
返回主外部文件系统上目录的绝对路径(位于应用程序可以放置其拥有的缓存文件的某个位置 ExternalStorageDirectory )。 (继承自 ContextWrapper) |
FilesDir |
返回存储使用 OpenFileOutput(String, FileCreationMode) 文件创建的文件系统上的目录的绝对路径。 (继承自 ContextWrapper) |
ForegroundServiceType |
如果服务已通过调用成为前台服务 |
Handle |
基础 Android 实例的句柄。 (继承自 Object) |
IsDeviceProtectedStorage |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 ContextWrapper) |
IsRestricted |
指示此上下文是否受到限制。 (继承自 Context) |
IsUiContext |
如果 |
JniIdentityHashCode |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
JniPeerMembers |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 |
MainExecutor |
|
MainLooper |
返回当前进程的主线程的 Looper。 (继承自 ContextWrapper) |
NoBackupFilesDir |
返回文件系统上目录的绝对路径,类似于 FilesDir. (继承自 ContextWrapper) |
ObbDir |
返回可在其中找到此应用程序的 OBB 文件(如果有)的主外部存储目录。 (继承自 ContextWrapper) |
OpPackageName |
返回应该用于 |
PackageCodePath |
返回此上下文的主要 Android 包的完整路径。 (继承自 ContextWrapper) |
PackageManager |
返回 PackageManager 实例以查找全局包信息。 (继承自 ContextWrapper) |
PackageName |
返回此应用程序的包的名称。 (继承自 ContextWrapper) |
PackageResourcePath |
返回此上下文的主要 Android 包的完整路径。 (继承自 ContextWrapper) |
Params |
返回创建此上下文时所使用的参数集(如果通过该 |
PeerReference |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
Resources |
返回应用程序的包的资源实例。 (继承自 ContextWrapper) |
Theme |
返回与此上下文关联的 Theme 对象。 (继承自 ContextWrapper) |
ThresholdClass |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 |
ThresholdType |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 |
Wallpaper | (继承自 ContextWrapper) |
WallpaperDesiredMinimumHeight | (继承自 ContextWrapper) |
WallpaperDesiredMinimumWidth | (继承自 ContextWrapper) |
方法
显式接口实现
IJavaPeerable.Disposed() |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
IJavaPeerable.DisposeUnlessReferenced() |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
IJavaPeerable.Finalized() |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
IJavaPeerable.JniManagedPeerState |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 (继承自 Object) |
扩展方法
JavaCast<TResult>(IJavaObject) |
执行 Android 运行时检查的类型转换。 |
JavaCast<TResult>(IJavaObject) |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 |
GetJniTypeName(IJavaPeerable) |
此服务由希望提供用于管理电话呼叫的功能的应用实现。 |