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;
}