在 Android 10 上使用 action_call 意图拨打电话不起作用 [英] Make a call using action_call intent on Android 10 doesn't work
本文介绍了在 Android 10 上使用 action_call 意图拨打电话不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这适用于以前版本的 android,但在 android 10 上不再适用.任何想法如何解决这个问题.任何帮助将不胜感激 .我已经尝试过来自 TelecomManager 的意图 action_call 和 placeCall.
This works on the previous version of android but on android 10 it no longer works . any ideas how to solve this problem. any help would be greatly appreciated . I have tried with intent action_call and placeCall from telecomManager.
/**
* Call a given number
*
* @param context
* @param number
*/
public static void call(@NotNull Context context, @NotNull String number) {
try {
// Create call intent
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode(number)));
// Handle sim card selection
// int simCard = getSimSelection(context);
// Timber.d("simcard "+simCard);
// if (simCard != -1) callIntent.putExtra("com.android.phone.extra.slot", simCard);
callIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
// 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();
}
}
/**
* Places a new outgoing call to the provided address using the system telecom service with
* the specified intent.
*
* @param activity {@link Activity} used to start another activity for the given intent
* @param telecomManager the {@link TelecomManager} used to place a call, if possible
* @param intent the intent for the call
*/
public static boolean placeCall(@Nullable FragmentActivity activity,
@Nullable TelecomManager telecomManager, @Nullable Intent intent) {
if (activity == null || telecomManager == null || intent == null) {
return false;
}
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return false;
}
telecomManager.placeCall(intent.getData(), intent.getExtras());
return true;
// activity.startActivityForResult(intent, 1291);
// return true;
}
推荐答案
如果在设置呼叫前未选择帐户,则需要您额外发送帐户句柄.
If the account is not selected before placing a call in setting it requires you to send a account handle as an extra.
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();
}
这篇关于在 Android 10 上使用 action_call 意图拨打电话不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文