CallScreeningService 中的 onScreenCall() 方法没有被调用,我希望此函数获取通话详细信息

问题描述 投票:0回答:3

我正在使用以下代码在清单中注册服务。

 <service android:name=".CallScreenService"
            android:permission="android.permission.BIND_SCREENING_SERVICE">
            <intent-filter>
                <action android:name="android.telecom.CallScreeningService"/>
            </intent-filter>
        </service>

这是我的服务类,它扩展了 CallScreeningService。

@RequiresApi(api = Build.VERSION_CODES.N)
public class CallScreenService extends CallScreeningService {

    @Override
    public void onScreenCall(Call.Details callDetails) {
        CallResponse.Builder response = new CallResponse.Builder();
        Toast.makeText(this, callDetails.getHandle().toString(), Toast.LENGTH_LONG).show();
    }
}
android android-studio service
3个回答
0
投票

您必须先注册您的应用程序以进行呼叫筛选角色:

https://developer.android.com/reference/android/telecom/CallScreeningService#onScreenCall(android.telecom.Call.Details)

 private static final int REQUEST_ID = 1;

 public void requestRole() {
     RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
     Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING);
     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 call screening app
         } else {
             // Your app is not the call screening app
         }
     }
 }
 

0
投票

如果您已实施

onStartCommand
,请将其删除。也删除
onBind
onUnbind


0
投票

需要权限

permission.READ_CALL_LOG,permission.READ_CONTACTS
© www.soinside.com 2019 - 2024. All rights reserved.