Example usage for android.content Context TELEPHONY_SERVICE

List of usage examples for android.content Context TELEPHONY_SERVICE

Introduction

In this page you can find the example usage for android.content Context TELEPHONY_SERVICE.

Prototype

String TELEPHONY_SERVICE

To view the source code for android.content Context TELEPHONY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.

Usage

From source file:com.wbtech.common.CommonUtil.java

/**
 * ?deviceid/*  w  w  w.  j a  v  a2 s . c o m*/
 * @param context
 *             <uses-permission android:name="READ_PHONE_STATE" /> 
 * @return
 */
public static String getDeviceID(Context context) {
    if (checkPermissions(context, "android.permission.READ_PHONE_STATE")) {
        String deviceId = "";
        if (checkPhoneState(context)) {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            deviceId = tm.getDeviceId();
        }
        if (deviceId != null) {
            if (UmsConstants.DebugMode) {
                Log.d("commonUtil", "deviceId:" + deviceId);
            }

            return deviceId;
        } else {
            if (UmsConstants.DebugMode) {
                Log.e("commonUtil", "deviceId is null");
            }

            return null;
        }
    } else {
        if (UmsConstants.DebugMode) {
            Log.e("lost permissioin", "lost----->android.permission.READ_PHONE_STATE");
        }

        return "";
    }
}

From source file:com.prey.net.PreyWebServices.java

/**
 * Register a new device for a given API_KEY, needed just after obtain the
 * new API_KEY.//from w w w .  j  av  a  2  s. c o  m
 * 
 * @throws PreyException
 */
private PreyHttpResponse registerNewDevice(Context ctx, String api_key, String deviceType)
        throws PreyException {
    PreyConfig preyConfig = PreyConfig.getPreyConfig(ctx);

    String model = Build.MODEL;
    String vendor = "Google";
    if (!PreyConfig.getPreyConfig(ctx).isCupcakeOrAbove())
        vendor = AboveCupcakeSupport.getDeviceVendor();

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("api_key", api_key);
    parameters.put("title", vendor + " " + model);
    parameters.put("device_type", deviceType);
    parameters.put("os", "Android");
    parameters.put("os_version", Build.VERSION.RELEASE);
    parameters.put("referer_device_id", "");
    parameters.put("plan", "free");
    parameters.put("activation_phrase", preyConfig.getSmsToRun());
    parameters.put("deactivation_phrase", preyConfig.getSmsToStop());
    parameters.put("model_name", model);
    parameters.put("vendor_name", vendor);

    parameters = increaseData(ctx, parameters);
    TelephonyManager mTelephonyMgr = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    //String imsi = mTelephonyMgr.getSubscriberId();
    String imei = mTelephonyMgr.getDeviceId();
    parameters.put("physical_address", imei);

    PreyHttpResponse response = null;
    try {
        String apiv2 = FileConfigReader.getInstance(ctx).getApiV2();
        String url = PreyConfig.getPreyConfig(ctx).getPreyUrl().concat(apiv2).concat("devices.json");
        PreyLogger.d("url:" + url);
        response = PreyRestHttpClient.getInstance(ctx).post(url, parameters);
        PreyLogger.d("response:" + response.getStatusLine() + " " + response.getResponseAsString());
        // No more devices allowed

        if ((response.getStatusLine().getStatusCode() == 302)
                || (response.getStatusLine().getStatusCode() == 422)
                || (response.getStatusLine().getStatusCode() == 403)) {
            throw new NoMoreDevicesAllowedException(
                    ctx.getText(R.string.set_old_user_no_more_devices_text).toString());
        }
        if (response.getStatusLine().getStatusCode() > 299) {
            throw new PreyException(ctx.getString(R.string.error_cant_add_this_device,
                    "[" + response.getStatusLine().getStatusCode() + "]"));
        }
    } catch (IOException e) {
        throw new PreyException(ctx.getText(R.string.error_communication_exception).toString(), e);
    }

    return response;
}

From source file:com.justinbull.ichnaeachecker.MainActivity.java

public void setCellInfo() {
    int tmPermCheck = ContextCompat.checkSelfPermission(MainActivity.this,
            android.Manifest.permission.ACCESS_COARSE_LOCATION);
    if (tmPermCheck == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
                && tm.getAllCellInfo() != null) {
            mVisibleCells = GeneralCellInfoFactory.getInstances(tm.getAllCellInfo());
            // Sort cells by strength
            Collections.sort(mVisibleCells, new Comparator<GeneralCellInfo>() {
                @Override/*from   w  ww.j  av a  2s  .  c o  m*/
                public int compare(GeneralCellInfo lhs, GeneralCellInfo rhs) {
                    int lhsDbm = lhs.getAsuStrength();
                    int rhsDbm = rhs.getAsuStrength();
                    if (lhsDbm == rhsDbm) {
                        return 0;
                    }
                    return lhsDbm > rhsDbm ? -1 : 1;
                }
            });
            mRegisteredCells.clear();
            if (mVisibleCells.size() == 0) {
                Log.w(TAG, "setCellInfo: No visible cells (primary or neighbours), unable to do anything");
            }
            for (GeneralCellInfo cell : mVisibleCells) {
                Log.i(TAG, "Device aware of " + cell.toString());
                if (cell.isRegistered()) {
                    mRegisteredCells.add(cell);
                }
            }
            if (mRegisteredCells.isEmpty()) {
                Log.w(TAG, "setCellInfo: No registered cells, nothing to select.");
                mSelectedCell = null;
            } else {
                Log.i(TAG, "setCellInfo: Preselected strongest registered cell: " + mRegisteredCells.get(0));
                mSelectedCell = mRegisteredCells.get(0);
            }
        } else {
            Log.e(TAG,
                    "setCellInfo: Android device too old to use getAllCellInfo(), need to implement getCellLocation() fallback!");
        }
        mCellListAdapter = new ArrayAdapter<GeneralCellInfo>(this, android.R.layout.simple_list_item_1,
                mVisibleCells);
    } else if (tmPermCheck == PackageManager.PERMISSION_DENIED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
                android.Manifest.permission.ACCESS_COARSE_LOCATION)) {
            Toast.makeText(MainActivity.this, "Dude we need permissions", Toast.LENGTH_LONG).show();
        }
        ActivityCompat.requestPermissions(MainActivity.this,
                new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION },
                Consts.REQUEST_COARSE_LOCATION);
    } else {
        Log.wtf(TAG, "setCellInfo: Received unknown int from ContextCompat.checkSelfPermission()");
    }
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static boolean isGSMPhone(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int phoneType = telephonyManager.getPhoneType();
    return phoneType == TelephonyManager.PHONE_TYPE_GSM;
}

From source file:com.compal.telephonytest.TelephonyTest.java

protected void setUp() throws Exception {
    super.setUp();

    loadConfig();/*from   w w  w . j  a va  2  s. c  o m*/
    mTelephonyManager = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    context = getInstrumentation().getTargetContext();
    mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (mConnectivityManager == null) {
        isConnectivityManagerNull = true;
        Log.i(tag, "isConnectivityManagerNull = true");
    }

    if (context == null) {
        isContextNull = true;
        Log.i(tag, "isContextNull = true");
    }

    if (mTelephonyManager == null) {
        isTelephonyManagerNull = true;
        mLog = "TelephonyManager is null";
        Log.i(tag, "isTelephonyManagerNull = true");
    }

}

From source file:org.ednovo.goorusearchwidget.SearchResults_resource.java

@Override
protected void onStart() {
    super.onStart();

    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    imeicode = tm.getDeviceId();/*from w ww. j a v  a  2 s  .c  om*/

    new httppoststart().execute();
    if (flag_isPlayerTransition) {
        flag_isPlayerTransition = false;
        resourceType = "";
        resourceGooruId = "";
    }

    Log.i("onStartSearchRes", "onStart");
}

From source file:com.att.android.arodatacollector.main.AROCollectorService.java

/**
 * Gets processing when an AROCollectorService object is created.
 * Overrides the android.app.Service#onCreate method.
 * //from  w w w  .  j  a  v a 2s  . c  om
 * @see android.app.Service#onCreate()
 */
@Override
public void onCreate() {

    // Initializes the data controls and starts the Data Collector trace
    // (i.e tcpdump,VideoCapture)
    mDataCollectorService = this;
    mApp = (ARODataCollector) getApplication();
    mAroUtils = new AROCollectorUtils();

    //flurry start session if set to is true.  set to false to disable FlurryAgent logging call.
    FlurryAgent.setLogEvents(isFlurryLogEventsEnabled);

    //check for flurry api key override from default-incorrect key will cause session to not log to correct Flurry app.
    setFlurryApiKey();
    FlurryAgent.setContinueSessionMillis(5000); // Set session timeout to 5 seconds (minimum specified by flurry)

    FlurryAgent.onStartSession(this, mApp.app_flurry_api_key); //don't use mAroCollectorService as context
    if (DEBUG) {
        Log.d(TAG, "onCreate called: " + mAroUtils.getSystemTimeinSeconds());
        Log.d(TAG, "flurry-called onStartSession");
    }

    //set device id as flurry's userid within a session
    final TelephonyManager mAROtelManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    FlurryAgent.setUserId(mAROtelManager.getDeviceId());
    if (DEBUG) {
        Log.d(TAG, "flurry-TelephonyManager deviceId: " + mAROtelManager.getDeviceId());
    }
    disableScreenTimeout();
    TRACE_FOLDERNAME = mApp.getDumpTraceFolderName();
    mVideoRecording = mApp.getCollectVideoOption();
    startDataCollectorVideoCapture();
    statDataCollectortcpdumpCapture();
    startDataCollectorDmesgCapture();
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static boolean isSimMissing(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int simState = telephonyManager.getSimState();
    return simState == TelephonyManager.SIM_STATE_ABSENT || simState == TelephonyManager.SIM_STATE_UNKNOWN;
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

private boolean handleCheckLicense(Context context, Intent intent) {
    String user = intent.getStringExtra(Intent.EXTRA_USER);
    Map<String, Set<String>> users = new LinkedHashMap<String, Set<String>>();
    for (Account account : ActivityManagerServiceHook.getAccountWatcher().getEnabledAccounts()) {
        Set<String> accounts = users.get(account.type);
        if (accounts == null) {
            accounts = new LinkedHashSet<String>();
            users.put(account.type, accounts);
        }//from  w w  w  .  jav  a  2  s  .c  o  m
        accounts.add(account.name);
        if (PackageUtils.equals(account.name, user)) {
            setResultCode(0x1);
            return true;
        }
    }
    String number = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
    if (number != null) {
        number = number.replace("-", "");
        number = number.replace(" ", "");
        Set<String> numbers = users.get("");
        if (numbers == null) {
            numbers = new LinkedHashSet<String>();
            users.put("", numbers);
        }
        numbers.add(number);
        if (PackageUtils.equals(number, user)) {
            setResultCode(0x1);
            return true;
        }
    }
    setResultCode(0x0);
    setResultData(users.toString());
    return false;
}