Example usage for android.telephony TelephonyManager getPhoneType

List of usage examples for android.telephony TelephonyManager getPhoneType

Introduction

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

Prototype

public int getPhoneType() 

Source Link

Document

Returns a constant indicating the device phone type.

Usage

From source file:com.android.bluetooth.map.BluetoothMapContent.java

public byte[] getSmsMessage(long id, int charset) throws UnsupportedEncodingException {
    int type, threadId;
    long time = -1;
    String msgBody;/*from   w ww .j  a va 2  s  .  c  o  m*/
    BluetoothMapbMessageSms message = new BluetoothMapbMessageSms();
    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);

    Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, "_ID = " + id, null, null);
    if (c == null || !c.moveToFirst()) {
        throw new IllegalArgumentException("SMS handle not found");
    }

    try {
        if (V)
            Log.v(TAG, "c.count: " + c.getCount());

        if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
            message.setType(TYPE.SMS_GSM);
        } else if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
            message.setType(TYPE.SMS_CDMA);
        } else {
            // set SMS_GSM by default
            message.setType(TYPE.SMS_GSM);
        }

        String read = c.getString(c.getColumnIndex(Sms.READ));
        if (read.equalsIgnoreCase("1"))
            message.setStatus(true);
        else
            message.setStatus(false);

        type = c.getInt(c.getColumnIndex(Sms.TYPE));
        threadId = c.getInt(c.getColumnIndex(Sms.THREAD_ID));
        message.setFolder(getFolderName(type, threadId));

        msgBody = c.getString(c.getColumnIndex(Sms.BODY));

        String phone = c.getString(c.getColumnIndex(Sms.ADDRESS));

        time = c.getLong(c.getColumnIndex(Sms.DATE));
        if (type == 1) // Inbox message needs to set the vCard as originator
            setVCardFromPhoneNumber(message, phone, true);
        else // Other messages sets the vCard as the recipient
            setVCardFromPhoneNumber(message, phone, false);

        if (charset == MAP_MESSAGE_CHARSET_NATIVE) {
            if (type == 1) //Inbox
                message.setSmsBodyPdus(BluetoothMapSmsPdu.getDeliverPdus(msgBody, phone, time));
            else
                message.setSmsBodyPdus(BluetoothMapSmsPdu.getSubmitPdus(msgBody, phone));
        } else /*if (charset == MAP_MESSAGE_CHARSET_UTF8)*/ {
            message.setSmsBody(msgBody);
        }
    } finally {
        close(c);
    }

    return message.encode();
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

String getPhoneType() {
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    int phoneType = telephonyManager.getPhoneType();
    switch (phoneType) {
    case TelephonyManager.PHONE_TYPE_NONE:
        return "NONE";

    case TelephonyManager.PHONE_TYPE_GSM:
        return "GSM";

    case TelephonyManager.PHONE_TYPE_CDMA:
        return "CDMA";

    /*//from w  w w . jav  a 2 s . c o  m
     *  for API Level 11 or above
     *  case TelephonyManager.PHONE_TYPE_SIP:
     *   return "SIP";
     */

    default:
        return "UNKNOWN";
    }
}

From source file:org.telegram.ui.PassportActivity.java

private void startPhoneVerification(boolean checkPermissions, final String phone, Runnable finishRunnable,
        ErrorRunnable errorRunnable, final PassportActivityDelegate delegate) {
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext
            .getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT
            && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (getParentActivity() != null && Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        allowCall = getParentActivity()// w  ww.j  a  va  2s  .  com
                .checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!permissionsItems.isEmpty()) {
                if (getParentActivity()
                        .shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(
                            permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                pendingPhone = phone;
                pendingErrorRunnable = errorRunnable;
                pendingFinishRunnable = finishRunnable;
                pendingDelegate = delegate;
                return;
            }
        }
    }
    final TLRPC.TL_account_sendVerifyPhoneCode req = new TLRPC.TL_account_sendVerifyPhoneCode();
    req.phone_number = phone;
    req.settings = new TLRPC.TL_codeSettings();
    req.settings.allow_flashcall = simcardAvailable && allowCall;
    if (Build.VERSION.SDK_INT >= 26) {
        try {
            req.settings.app_hash = SmsManager.getDefault()
                    .createAppSpecificSmsToken(PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                            0, new Intent(ApplicationLoader.applicationContext, SmsReceiver.class),
                            PendingIntent.FLAG_UPDATE_CURRENT));
        } catch (Throwable e) {
            FileLog.e(e);
        }
    } else {
        req.settings.app_hash = BuildVars.SMS_HASH;
        req.settings.app_hash_persistent = true;
    }
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    if (!TextUtils.isEmpty(req.settings.app_hash)) {
        req.settings.flags |= 8;
        preferences.edit().putString("sms_hash", req.settings.app_hash).commit();
    } else {
        preferences.edit().remove("sms_hash").commit();
    }
    if (req.settings.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds")
            String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.settings.current_number = phone.contains(number) || number.contains(phone);
                if (!req.settings.current_number) {
                    req.settings.allow_flashcall = false;
                }
            } else {
                req.settings.current_number = false;
            }
        } catch (Exception e) {
            req.settings.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    ConnectionsManager.getInstance(currentAccount).sendRequest(req,
            (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                if (error == null) {
                    HashMap<String, String> values = new HashMap<>();
                    values.put("phone", phone);
                    PassportActivity activity = new PassportActivity(TYPE_PHONE_VERIFICATION, currentForm,
                            currentPassword, currentType, null, null, null, values, null);
                    activity.currentAccount = currentAccount;
                    activity.saltedPassword = saltedPassword;
                    activity.secureSecret = secureSecret;
                    activity.delegate = delegate;
                    activity.currentPhoneVerification = (TLRPC.TL_auth_sentCode) response;
                    presentFragment(activity, true);
                } else {
                    AlertsCreator.processError(currentAccount, error, PassportActivity.this, req, phone);
                }
            }), ConnectionsManager.RequestFlagFailOnServerErrors);
}