@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_CALL: { if (mCursor != null && mCursor.moveToPosition(getSelectedItemPosition())) { String phoneNumber = mCursor.getString(NUMBER_COLUMN); if (phoneNumber == null || !TextUtils.isGraphic(phoneNumber)) { // There is no number entered. // TODO play error sound or something... return true; } Intent intent = new Intent( Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts(Constants.SCHEME_TEL, phoneNumber, null)); intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); startActivity(intent); finish(); return true; } } } return super.onKeyDown(keyCode, event); }
/** * Method that check if a character is valid printable character * * @param c The character to check * @return boolean If the character is printable * @hide */ static boolean isPrintableCharacter(char c) { int cc = VALID_NON_PRINTABLE_CHARS.length; for (int i = 0; i < cc; i++) { if (c == VALID_NON_PRINTABLE_CHARS[i]) { return true; } } return TextUtils.isGraphic(c); }