Example usage for android.telephony TelephonyManager getVoiceMailNumber

List of usage examples for android.telephony TelephonyManager getVoiceMailNumber

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getVoiceMailNumber.

Prototype

@SuppressAutoDoc 
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getVoiceMailNumber() 

Source Link

Document

Returns the voice mail number.

Usage

From source file:com.newcell.calltext.ui.dialpad.DialerFragment.java

/**
 * Place a Voicemail call (*86)//from w w  w  . j  a va  2  s .co  m
 */
public void placeVMCall() {
    Long accountToUse = SipProfile.INVALID_ID;
    SipProfile acc = null;
    acc = accountChooserButton.getSelectedAccount();
    if (acc == null) {
        // Maybe we could inform user nothing will happen here?
        return;
    }

    accountToUse = acc.id;

    if (accountToUse >= 0) {

        Log.i(THIS_FILE, "PlaceVMCall - User account found");

        digits.setText("*86");
        placeCall();

        /*
         * 08/06/2014 Changed Voicemail to just call *86
                 
         SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id, new String[] {
            SipProfile.FIELD_VOICE_MAIL_NBR
         });
         if (!TextUtils.isEmpty(vmAcc.vm_nbr)) {
        // Account already has a VM number
        try {
            service.makeCall(vmAcc.vm_nbr, (int) acc.id);
        } catch (RemoteException e) {
            Log.e(THIS_FILE, "Service can't be called to make the call");
        }
         } else {
        // Account has no VM number, get the users phone number to use
            String vmNumber = acc.getSipUserName();
            if(!TextUtils.isEmpty(vmNumber)) {
                  
          final long editedAccId = acc.id;
          vmAcc.vm_nbr = vmNumber;
                  
          ContentValues cv = new ContentValues();
            cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber);
                
            int updated = getActivity().getContentResolver()
                    .update(ContentUris.withAppendedId(
                            SipProfile.ACCOUNT_ID_URI_BASE,
                            editedAccId),
                            cv, null, null);
                    
            Log.d(THIS_FILE, "Updated accounts " + updated);
          try {
             service.makeCall(vmAcc.vm_nbr, (int) acc.id);
          } catch(RemoteException e) {
             Log.e(THIS_FILE, "Service can't be called to make the call");
          }
            } else {
          Toast.makeText(getActivity(), "Account phone number has not been set", Toast.LENGTH_SHORT).show();
            }
         }
                 
          * 08/06/2014 Changed Voicemail to just call *86
          */
    } else if (accountToUse == CallHandlerPlugin.getAccountIdForCallHandler(getActivity(),
            (new ComponentName(getActivity(), CallHandler.class).flattenToString()))) {
        // Case gsm voice mail

        Log.i(THIS_FILE, "PlaceVMCall - GSM voicemail");

        TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String vmNumber = tm.getVoiceMailNumber();

        if (!TextUtils.isEmpty(vmNumber)) {
            if (service != null) {
                try {
                    service.ignoreNextOutgoingCallFor(vmNumber);
                } catch (RemoteException e) {
                    Log.e(THIS_FILE, "Not possible to ignore next");
                }
            }
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm)
                    .setMessage(R.string.no_voice_mail_configured)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    }
    // TODO : manage others ?... for now, no way to do so cause no vm stored
}

From source file:com.fututel.ui.dialpad.DialerFragment.java

public void placeVMCall() {
    Long accountToUse = SipProfile.INVALID_ID;
    SipProfile acc = null;/*from w ww.j a va2  s. com*/
    acc = accountChooserButton.getSelectedAccount();
    if (acc != null) {
        accountToUse = acc.id;
    }

    if (accountToUse >= 0) {
        SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id,
                new String[] { SipProfile.FIELD_VOICE_MAIL_NBR });
        if (!TextUtils.isEmpty(vmAcc.vm_nbr)) {
            // Account already have a VM number
            try {
                service.makeCall(vmAcc.vm_nbr, (int) acc.id);
            } catch (RemoteException e) {
                Log.e(THIS_FILE, "Service can't be called to make the call");
            }
        } else {
            // Account has no VM number, propose to create one
            final long editedAccId = acc.id;
            LayoutInflater factory = LayoutInflater.from(getActivity());
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(acc.display_name)
                    .setView(textEntryView)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            if (missingVoicemailDialog != null) {
                                TextView tf = (TextView) missingVoicemailDialog.findViewById(R.id.vmfield);
                                if (tf != null) {
                                    String vmNumber = tf.getText().toString();
                                    if (!TextUtils.isEmpty(vmNumber)) {
                                        ContentValues cv = new ContentValues();
                                        cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber);

                                        int updated = getActivity().getContentResolver()
                                                .update(ContentUris.withAppendedId(
                                                        SipProfile.ACCOUNT_ID_URI_BASE, editedAccId), cv, null,
                                                        null);
                                        Log.d(THIS_FILE, "Updated accounts " + updated);
                                    }
                                }
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    } else if (accountToUse == CallHandlerPlugin.getAccountIdForCallHandler(getActivity(),
            (new ComponentName(getActivity(), com.fututel.plugins.telephony.CallHandler.class)
                    .flattenToString()))) {
        // Case gsm voice mail
        TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String vmNumber = tm.getVoiceMailNumber();

        if (!TextUtils.isEmpty(vmNumber)) {
            if (service != null) {
                try {
                    service.ignoreNextOutgoingCallFor(vmNumber);
                } catch (RemoteException e) {
                    Log.e(THIS_FILE, "Not possible to ignore next");
                }
            }
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm)
                    .setMessage(R.string.no_voice_mail_configured)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    }
    // TODO : manage others ?... for now, no way to do so cause no vm stored
}