Example usage for android.telephony TelephonyManager getDeviceId

List of usage examples for android.telephony TelephonyManager getDeviceId

Introduction

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

Prototype

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

Source Link

Document

Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.

Usage

From source file:com.xdyou.sanguo.GameSanGuo.java

public static String getMacID() {
    String str = "mac_address";

    WifiManager wifi = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    str = info.getMacAddress();// w  w  w . j a v  a2 s .  c om

    // ??imei?
    if (str == null) {
        TelephonyManager tm = (TelephonyManager) mActivity.getSystemService(TELEPHONY_SERVICE);
        str = tm.getDeviceId();
    }
    Log.e("mac_address", str);
    return str;
}

From source file:com.example.hbranciforte.trafficclient.History.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String token = telephonyManager.getDeviceId().toString();
    //HttpPost httppostreq = new HttpPost("http://10.0.2.2:3000/parkings??notification_token=".concat(token));
    ListView listView = (ListView) findViewById(R.id.historyable);

    try {/*from  w w  w.ja  v  a2s.  com*/
        HttpClient client = new DefaultHttpClient();
        String getURL = "http://45.55.79.197/parkings?notification_token=".concat(token);
        //String getURL = "http://10.0.2.2:3000/parkings?notification_token=".concat(token);
        HttpGet get = new HttpGet(getURL);
        HttpResponse responseGet = client.execute(get);
        HttpEntity resEntityGet = responseGet.getEntity();
        if (resEntityGet != null) {
            String response = EntityUtils.toString(resEntityGet);
            data = new JSONArray(response);

            String[] values = new String[data.length()];
            for (int i = 0; i < this.data.length(); i++) {
                JSONObject parking = new JSONObject(data.get(i).toString());
                JSONObject zone = new JSONObject(parking.getString("zone"));
                JSONObject car = new JSONObject(parking.getString("car"));
                String temp = "Patente: ".concat(car.getString("license_plate")).concat("\n");
                temp = temp.concat("Zona: ").concat(zone.getString("name")).concat("-")
                        .concat(Integer.toString(zone.getInt("number")).concat("\n"));
                temp = temp.concat("Estado: ").concat(parking.getString("status")).concat("\n");
                values[i] = temp.concat("Valido hasta: ").concat(parking.getString("formated_expires_at"));

            }
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    android.R.id.text1, values);
            listView.setAdapter(adapter);
        }
    } catch (Exception e) {
        Log.e("Error Parsing:", e.getMessage());
    }

}

From source file:com.aegiswallet.tasks.SendShamirValueTask.java

@Override
protected Object doInBackground(Object[] objects) {

    httpclient = new DefaultHttpClient();
    httppost = new HttpPost(Constants.AEGIS_SITE);

    Log.d(TAG, "sending shamir");
    try {/*from  w  ww. j a va 2s  .  c  o  m*/
        // Add your data

        TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String uid = tManager.getDeviceId();

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("device", uid));
        nameValuePairs.add(new BasicNameValuePair("message", x3Value));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        int statusCode = response.getStatusLine().getStatusCode();

        Log.d(TAG, "response for shamir: " + statusCode);

        if (statusCode != 200) {
            //TODO: did not succeed
        } else {
            //Means we have successfully exported the key to BitcoinSecurityProject.org
            application.getPrefs().edit().remove(Constants.SHAMIR_EXPORTED_KEY).commit();
        }

    } catch (ClientProtocolException e) {
        Log.d(TAG, e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, e.getMessage());
    }
    return null;
}

From source file:com.polyvi.xface.extension.devicecapability.XDeviceCapabilityExt.java

/**
 * ?deviceInternational Mobile Equipment Identity(IMEI)
 *
 * @param context/*from   w w  w  .  j  a v a2  s .  c om*/
 * @return
 */
private String getImei(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getDeviceId();
}

From source file:me.oss.tracker.trackme.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.context = this;

    textView = (TextView) findViewById(R.id.deviceID);

    /* Handset mac*/
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String device_id = tm.getDeviceId();
    textView.setText(device_id + "");

    Intent alarm = new Intent(this.context, AlarmReceiver.class);
    boolean alarmRunning = (PendingIntent.getBroadcast(this.context, 0, alarm,
            PendingIntent.FLAG_NO_CREATE) != null);
    if (alarmRunning == false) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this.context, 0, alarm, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),
                LocalLog.syn_time, pendingIntent);
    }//from   w  w  w  . j a v  a  2s  .  com

    mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                mInformationTextView.setText(getString(R.string.gcm_send_message));
            } else {
                mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };
    mInformationTextView = (TextView) findViewById(R.id.informationTextView);

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

From source file:com.phonegap.Device.java

public String getDeviceId() {
    TelephonyManager operator = (TelephonyManager) this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return operator.getDeviceId();
}

From source file:org.digitalcampus.oppia.utils.MetaDataUtils.java

public MetaDataUtils(Context ctx) {
    this.ctx = ctx;
    TelephonyManager manager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    networkProvider = manager.getNetworkOperatorName();
    deviceId = manager.getDeviceId();
    simSerial = manager.getSimSerialNumber();
}

From source file:it.scsoft.tiuuid.TitaniumUUIDModule.java

@Kroll.method
public String uuidForDevice() {

    // Serial//from w  w w  . j  ava  2s  . c  o  m
    String serial = android.os.Build.SERIAL;

    // IMEI
    String imei = "";
    if (ContextCompat.checkSelfPermission(TiApplication.getInstance().getApplicationContext(),
            Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager telephonyManager = (TelephonyManager) TiApplication.getInstance()
                .getSystemService(Context.TELEPHONY_SERVICE);
        imei = telephonyManager.getDeviceId();
    }

    // AndroidID
    String androidID = Secure.getString(TiApplication.getInstance().getContentResolver(), Secure.ANDROID_ID);

    // uuid
    String uuid = serial + imei + androidID;

    // MD5 hash via http://stackoverflow.com/questions/3934331/how-to-hash-a-string-in-android
    String hash = "";
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
        digest.update(uuid.getBytes(Charset.forName("US-ASCII")), 0, uuid.length());
        byte[] magnitude = digest.digest();
        BigInteger bi = new BigInteger(1, magnitude);
        hash = String.format("%0" + (magnitude.length << 1) + "x", bi);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    return hash;
}

From source file:eu.liveGov.libraries.livegovtoolkit.helper.UserInformationHelper.java

public void requestNewAnonymous(Context con) {
    logger.info("requestNewAnonymous;");
    _context = con;//from  w ww. j  av a 2 s. c o  m
    final TelephonyManager tm = (TelephonyManager) con.getSystemService(Context.TELEPHONY_SERVICE);

    String deviceId = tm.getDeviceId();
    logger.info("requestNewAnonymous; id: A_" + deviceId);
    new DownloadHelper(this).createAnonymousUser("A_" + deviceId);
}

From source file:com.cmput301.classproject.UI.AddTaskActivity.java

/**
 * /*from   w w  w  .j  a  v a 2s .  c  o  m*/
 * @returnThe ID of the phone this app is running on
 */
public String getPhoneID() {
    TelephonyManager tManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    String uid = tManager.getDeviceId();
    return uid;
}