Я пытаюсь получить экран родного входящего вызова, когда получаю уведомление pu sh. Я реализую класс ConnectionService и Telecom.
Это мой код активности класса
public class MainActivity extends AppCompatActivity {
TextView tvCall;
String packageName;
String className;
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvCall = findViewById(R.id.tvCall);
packageName = getApplicationContext().getPackageName();
className = MainActivity.class.getName();
tvCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCall();
}
});
}
@RequiresApi(api = Build.VERSION_CODES.M)
void showCall() {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE},
1);
TelecomManager telecomManager = (TelecomManager) this.getSystemService(Context.TELECOM_SERVICE);
//ComponentName componentName = new ComponentName(packageName, className);
//PhoneAccountHandle accountHandle = new PhoneAccountHandle(componentName, "Admin");
ComponentName cName = new ComponentName(packageName, className);
PhoneAccountHandle accountHandle = new PhoneAccountHandle(cName, "whatever you want");
PhoneAccount account = PhoneAccount.builder(accountHandle, "Admin")
.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
.build();
telecomManager.registerPhoneAccount(account);
Bundle extras = new Bundle();
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
extras.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
telecomManager.addNewIncomingCall(accountHandle, extras);
}
}
класс реализует ConnectionService
public class CallConnectionService extends ConnectionService {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
//return super.onCreateIncomingConnection(connectionManagerPhoneAccount, request);
//Log.d(TAG, "onCreateIncomingConnection");
CallManager connectionn = new CallManager();
connectionn.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
connectionn.setCallerDisplayName("TestID", TelecomManager.PRESENTATION_ALLOWED);
connectionn.setInitializing();
Bundle extras = new Bundle();
extras.putBoolean(Connection.EXTRA_ANSWERING_DROPS_FG_CALL, true);
extras.putString(Connection.EXTRA_CALL_SUBJECT, "Test call subject text");
connectionn.putExtras(extras);
return connectionn;
}
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
return super.onCreateOutgoingConnection(connectionManagerPhoneAccount, request);
}
}
и класс, который реализует Connection
@RequiresApi(api = Build.VERSION_CODES.M)
publi c класс CallManager расширяет соединение {
private static final String TAG = "yorman";
@Override
public void onShowIncomingCallUi() {
super.onShowIncomingCallUi();
Log.d(TAG, "onShowIncomingCallUi: ");
}
@Override
public void onCallAudioStateChanged(CallAudioState state) {
super.onCallAudioStateChanged(state);
Log.d(TAG, "onCallAudioStateChanged: ");
}
@Override
public void onHold() {
super.onHold();
Log.d(TAG, "onHold: ");
}
@Override
public void onUnhold() {
super.onUnhold();
Log.d(TAG, "onUnhold: ");
}
@Override
public void onAnswer() {
super.onAnswer();
Log.d(TAG, "onAnswer: ");
}
@Override
public void onReject() {
super.onReject();
Log.d(TAG, "onReject: ");
}
@Override
public void onDisconnect() {
super.onDisconnect();
Log.d(TAG, "onDisconnect: ");
}
}
проблема в том, что я не получаю звонок