android.telecom.PhoneAccountHandle Java Examples

The following examples show how to use android.telecom.PhoneAccountHandle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 7 votes vote down vote up
private PhoneAccountHandle subscriptionToPhoneAccountHandle(final SubscriptionInfo subInfo) {
    if (subInfo == null)
        return null;

    final TelecomManager telecomManager =
            (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
    final TelephonyManager telephonyManager =
            (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    final Iterator<PhoneAccountHandle> phoneAccounts =
            telecomManager.getCallCapablePhoneAccounts().listIterator();
    while (phoneAccounts.hasNext()) {
        final PhoneAccountHandle phoneAccountHandle = phoneAccounts.next();
        final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle);
        if (subInfo.getSubscriptionId() == getSubIdForPhoneAccount(telephonyManager, phoneAccount)) {
            return phoneAccountHandle;
        }
    }

    return null;
}
 
Example #2
Source File: VoicemailContract.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Maps structured {@link Voicemail} to {@link ContentValues} in content provider.
 */
private static ContentValues getContentValues(Voicemail voicemail) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(Voicemails.DATE, String.valueOf(voicemail.getTimestampMillis()));
    contentValues.put(Voicemails.NUMBER, voicemail.getNumber());
    contentValues.put(Voicemails.DURATION, String.valueOf(voicemail.getDuration()));
    contentValues.put(Voicemails.SOURCE_PACKAGE, voicemail.getSourcePackage());
    contentValues.put(Voicemails.SOURCE_DATA, voicemail.getSourceData());
    contentValues.put(Voicemails.IS_READ, voicemail.isRead() ? 1 : 0);

    PhoneAccountHandle phoneAccount = voicemail.getPhoneAccount();
    if (phoneAccount != null) {
        contentValues.put(Voicemails.PHONE_ACCOUNT_COMPONENT_NAME,
                phoneAccount.getComponentName().flattenToString());
        contentValues.put(Voicemails.PHONE_ACCOUNT_ID, phoneAccount.getId());
    }

    if (voicemail.getTranscription() != null) {
        contentValues.put(Voicemails.TRANSCRIPTION, voicemail.getTranscription());
    }

    return contentValues;
}
 
Example #3
Source File: TelegramConnectionService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateOutgoingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		if(!svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #4
Source File: TelegramConnectionService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateIncomingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		if(svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #5
Source File: TelegramConnectionService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateOutgoingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		if(!svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #6
Source File: TelegramConnectionService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateIncomingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		if(svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #7
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private int getDefaultVoiceSubscriptionSimSlot() {
    try {
        final TelecomManager telecomManager =
                (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        final TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        PhoneAccountHandle pah = (PhoneAccountHandle) XposedHelpers.callMethod(telecomManager,
                "getUserSelectedOutgoingPhoneAccount");
        if (pah != null) {
            PhoneAccount pa = telecomManager.getPhoneAccount(pah);
            int subId = getSubIdForPhoneAccount(telephonyManager, pa);
            SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfo(subId);
            if (si != null) {
                return si.getSimSlotIndex();
            }
        }
        return -1;
    } catch (Throwable t) {
        XposedBridge.log(t);
        return -1;
    }
}
 
Example #8
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private List<IIconListAdapterItem> getSubItemList(final SubType subType) {
    List<IIconListAdapterItem> list = new ArrayList<>();
    if (subType == SubType.VOICE) {
        list.add(new SubListItem(null));
        final TelecomManager telecomManager = 
                (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        final TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        final Iterator<PhoneAccountHandle> phoneAccounts =
                telecomManager.getCallCapablePhoneAccounts().listIterator();
        while (phoneAccounts.hasNext()) {
            final PhoneAccount phoneAccount =
                    telecomManager.getPhoneAccount(phoneAccounts.next());
            int subId = getSubIdForPhoneAccount(telephonyManager, phoneAccount);
            if (subId != -1) {
                list.add(new SubListItem(mSubMgr.getActiveSubscriptionInfo(subId)));
            }
        }
    } else {
        for (SubscriptionInfo si : mSubMgr.getActiveSubscriptionInfoList())
            if (si != null)
                list.add(new SubListItem(si));
    }
    return list;
}
 
Example #9
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateOutgoingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		if(!svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #10
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateIncomingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		if(svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #11
Source File: RNCallKeepModule.java    From react-native-callkeep with ISC License 6 votes vote down vote up
private void registerPhoneAccount(Context appContext) {
    if (!isConnectionServiceAvailable()) {
        return;
    }

    ComponentName cName = new ComponentName(this.getAppContext(), VoiceConnectionService.class);
    String appName = this.getApplicationName(appContext);

    handle = new PhoneAccountHandle(cName, appName);

    PhoneAccount.Builder builder = new PhoneAccount.Builder(handle, appName)
            .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER);

    if (_settings != null && _settings.hasKey("imageName")) {
        int identifier = appContext.getResources().getIdentifier(_settings.getString("imageName"), "drawable", appContext.getPackageName());
        Icon icon = Icon.createWithResource(appContext, identifier);
        builder.setIcon(icon);
    }

    PhoneAccount account = builder.build();

    telephonyManager = (TelephonyManager) this.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
    telecomManager = (TelecomManager) this.getAppContext().getSystemService(Context.TELECOM_SERVICE);

    telecomManager.registerPhoneAccount(account);
}
 
Example #12
Source File: DialerActivity.java    From BaldPhone with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void call(final CharSequence number, final Context context, SubscriptionInfo subscriptionInfo) {
    try {
        if (subscriptionInfo == null) {
            context.startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse(("tel:" + number).replace("#", Uri.encode("#")))));
        } else {
            final TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
            final List<PhoneAccountHandle> list = telecomManager.getCallCapablePhoneAccounts();
            for (final PhoneAccountHandle phoneAccountHandle : list) {
                if (phoneAccountHandle.getId().contains(subscriptionInfo.getIccId())) {
                    context.startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse(("tel:" + number).replace("#", Uri.encode("#"))))
                            .putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", (Parcelable) phoneAccountHandle));
                    return;
                }
            }
            BaldToast.error(context);

        }
    } catch (SecurityException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        throw new RuntimeException(e);
    }

}
 
Example #13
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateOutgoingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		if(!svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #14
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.d("onCreateIncomingConnection "/*+request*/);
	Bundle extras=request.getExtras();
	if(extras.getInt("call_type")==1){ // private
		VoIPService svc=VoIPService.getSharedInstance();
		if(svc==null)
			return null;
		if(svc.isOutgoing())
			return null;
		return svc.getConnectionAndStartCall();
	}else if(extras.getInt("call_type")==2){ // group
		/*VoIPGroupService svc=VoIPGroupService.getSharedInstance();
		if(svc==null)
			return null;
		return svc.getConnectionAndStartCall();*/
	}
	return null;
}
 
Example #15
Source File: TelecomLoaderService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void updateSimCallManagerPermissions(PackageManagerInternal packageManagerInternal,
        int userId) {
    TelecomManager telecomManager =
        (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
    PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId);
    if (phoneAccount != null) {
        Slog.i(TAG, "updating sim call manager permissions for userId:" + userId);
        String packageName = phoneAccount.getComponentName().getPackageName();
        packageManagerInternal.grantDefaultPermissionsToDefaultSimCallManager(
            packageName, userId);
    }
}
 
Example #16
Source File: TelegramConnectionService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateOutgoingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #17
Source File: TelegramConnectionService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateIncomingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #18
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
protected PhoneAccountHandle addAccountToTelecomManager(){
	TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
	TLRPC.User self=UserConfig.getInstance(currentAccount).getCurrentUser();
	PhoneAccountHandle handle=new PhoneAccountHandle(new ComponentName(this, TelegramConnectionService.class), ""+self.id);
	PhoneAccount account=new PhoneAccount.Builder(handle, ContactsController.formatName(self.first_name, self.last_name))
			.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
			.setIcon(Icon.createWithResource(this, R.drawable.ic_launcher_dr))
			.setHighlightColor(0xff2ca5e0)
			.addSupportedUriScheme("sip")
			.build();
	tm.registerPhoneAccount(account);
	return handle;
}
 
Example #19
Source File: TelegramConnectionService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateOutgoingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #20
Source File: TelegramConnectionService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateIncomingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #21
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
protected PhoneAccountHandle addAccountToTelecomManager(){
	TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
	TLRPC.User self=UserConfig.getInstance(currentAccount).getCurrentUser();
	PhoneAccountHandle handle=new PhoneAccountHandle(new ComponentName(this, TelegramConnectionService.class), ""+self.id);
	PhoneAccount account=new PhoneAccount.Builder(handle, ContactsController.formatName(self.first_name, self.last_name))
			.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
			.setIcon(Icon.createWithResource(this, R.drawable.ic_launcher))
			.setHighlightColor(0xff2ca5e0)
			.addSupportedUriScheme("sip")
			.build();
	tm.registerPhoneAccount(account);
	return handle;
}
 
Example #22
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
protected PhoneAccountHandle addAccountToTelecomManager(){
	TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
	TLRPC.User self=UserConfig.getInstance(currentAccount).getCurrentUser();
	PhoneAccountHandle handle=new PhoneAccountHandle(new ComponentName(this, TelegramConnectionService.class), ""+self.id);
	PhoneAccount account=new PhoneAccount.Builder(handle, ContactsController.formatName(self.first_name, self.last_name))
			.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
			.setIcon(Icon.createWithResource(this, R.drawable.ic_launcher_dr))
			.setHighlightColor(0xff2ca5e0)
			.addSupportedUriScheme("sip")
			.build();
	tm.registerPhoneAccount(account);
	return handle;
}
 
Example #23
Source File: TelecomTestUtils.java    From AndroidContacts with MIT License 5 votes vote down vote up
public static void registerSimPhoneAccount(Instrumentation instrumentation,
                                           PhoneAccountHandle handle, String label, String address) throws Exception {
    final ComponentName component = handle.getComponentName();
    executeShellCommand(instrumentation, COMMAND_REGISTER_SIM
        + component.getPackageName() + "/" + component.getClassName() + " "
        + handle.getId() + " " + label + " " + address);
}
 
Example #24
Source File: TelecomTestUtils.java    From AndroidContacts with MIT License 5 votes vote down vote up
public static void enablePhoneAccount(Instrumentation instrumentation,
                                      PhoneAccountHandle handle) throws Exception {
    final ComponentName component = handle.getComponentName();
    executeShellCommand(instrumentation, COMMAND_ENABLE
        + component.getPackageName() + "/" + component.getClassName() + " "
        + handle.getId());
}
 
Example #25
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateIncomingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #26
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateOutgoingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #27
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateOutgoingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #28
Source File: TelegramConnectionService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request){
	if(BuildVars.LOGS_ENABLED)
		FileLog.e("onCreateIncomingConnectionFailed "/*+request*/);
	if(VoIPBaseService.getSharedInstance()!=null){
		VoIPBaseService.getSharedInstance().callFailedFromConnectionService();
	}
}
 
Example #29
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
protected PhoneAccountHandle addAccountToTelecomManager(){
	TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
	TLRPC.User self=UserConfig.getInstance(currentAccount).getCurrentUser();
	PhoneAccountHandle handle=new PhoneAccountHandle(new ComponentName(this, TelegramConnectionService.class), ""+self.id);
	PhoneAccount account=new PhoneAccount.Builder(handle, ContactsController.formatName(self.first_name, self.last_name))
			.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
			.setIcon(Icon.createWithResource(this, R.drawable.ic_launcher))
			.setHighlightColor(0xff2ca5e0)
			.addSupportedUriScheme("sip")
			.build();
	tm.registerPhoneAccount(account);
	return handle;
}
 
Example #30
Source File: USSDController.java    From VoIpUSSD with Apache License 2.0 5 votes vote down vote up
/**
 * get action call Intent
 *
 * @param uri     parsed uri to call
 * @param simSlot simSlot number to use
 */
@SuppressLint("MissingPermission")
private Intent getActionCallIntent(Uri uri, int simSlot) {
    // https://stackoverflow.com/questions/25524476/make-call-using-a-specified-sim-in-a-dual-sim-device
    final String simSlotName[] = {
            "extra_asus_dial_use_dualsim",
            "com.android.phone.extra.slot",
            "slot",
            "simslot",
            "sim_slot",
            "subscription",
            "Subscription",
            "phone",
            "com.android.phone.DialingMode",
            "simSlot",
            "slot_id",
            "simId",
            "simnum",
            "phone_type",
            "slotId",
            "slotIdx"
    };

    Intent intent = new Intent(Intent.ACTION_CALL, uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("com.android.phone.force.slot", true);
    intent.putExtra("Cdma_Supp", true);

    for (String s : simSlotName)
        intent.putExtra(s, simSlot);

    TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecomManager != null) {
        List<PhoneAccountHandle> phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts();
        if (phoneAccountHandleList != null && phoneAccountHandleList.size() > simSlot)
            intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandleList.get(simSlot));
    }

    return intent;
}