问题描述
这适用于早期版本的android,但在android 10上不再适用。任何想法如何解决这个问题。任何帮助将不胜感激 。我已经尝试使用来自telecomManager的intent action_call和placeCall。
socket
解决方法
尝试添加callIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
,您是否要从后台服务开始通话?
Android 10仅限从后台启动活动。对此有一些排除。在我看来,“ SYSTEM_ALERT_WINDOW”权限是最简单的权限。
https://developer.android.com/guide/components/activities/background-starts
https://stackoverflow.com/a/59421118/11982611
private void RequestPermission() {
// Check if Android M or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Show alert dialog to the user saying a separate permission is needed
// Launch the settings activity if the user prefers
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,Uri.parse("package:" + getActivity().getPackageName()));
startActivityForResult(intent,ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE);
}
}
@Override
public void onActivityResult(int requestCode,int resultCode,@Nullable Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (requestCode == ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(getContext())) {
PermissionDenied();
}
else
{
//Permission Granted-System will work
}
}
}
,
如果在设置呼叫前未选择帐户,则需要额外发送一个帐户句柄。
try {
List<PhoneAccountHandle> phoneAccountHandleList = TelecomUtil.getTelecomManager(context).getCallCapablePhoneAccounts();
int simCard = getSimSelection(context);
// Create call intent
Intent callIntent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + Uri.encode(number)));
if (phoneAccountHandleList != null && !phoneAccountHandleList.isEmpty()) {
callIntent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,phoneAccountHandleList.get(simCard));
}
// // Handle sim card selection
Timber.d("simcard %s",simCard);
if (simCard != -1) callIntent.putExtra("com.android.phone.extra.slot",simCard);
// // Start the call
context.startActivity(callIntent);
} catch (SecurityException e) {
Toast.makeText(context,"Couldn't make a call due to security reasons",Toast.LENGTH_LONG).show();
} catch (NullPointerException e) {
Toast.makeText(context,"Couldnt make a call,no phone number",Toast.LENGTH_LONG).show();
}