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:org.hygieiasoft.cordova.uid.UID.java

/**
 * Get the device's International Mobile Station Equipment Identity (IMEI).
 *
 * @param context The context of the main Activity.
 * @return/* www.ja  va2s. c om*/
 */
public String getImei(Context context) {
    final TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = mTelephony.getDeviceId();
    return imei;
}

From source file:org.ubicompforall.BusTUC.Speech.HTTP.java

public CBRAnswer blackList(double lat, double lon, String prevGuess, Context context) {
    HttpClient client = new DefaultHttpClient();
    String response = "";
    CBRAnswer answ = null;/*from  ww  w. j  av a2  s . c o m*/
    Calculate calc = null;
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String t_id = tm.getDeviceId();
        String tmp = "TABuss";
        String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        HttpGet httpget = new HttpGet(
                "http://vm-6114.idi.ntnu.no:1337/SpeechServer/cbrGuess?lat=" + lat + "&lon=" + lon + "&devID="
                        + tmp + p_id + "&dest=" + URLEncoder.encode(prevGuess, "UTF-8") + "&blacklist=true");
        long first = System.nanoTime();
        response = EntityUtils.toString(client.execute(httpget).getEntity(), "UTF-8");
        calc = new Calculate();
        System.out.println("RESPONSE: " + response);
        answ = calc.createCBRAnswer(response);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return answ;
}

From source file:org.ubicompforall.BusTUC.Speech.HTTP.java

public CBRAnswer getCBRGuess(double lat, double lon, Context context) {
    HttpClient client = new DefaultHttpClient();
    String response = "";
    CBRAnswer answ = null;//from w  ww.  j  a va 2  s  .  c  o m
    Calculate calc = null;
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String t_id = tm.getDeviceId();
        String tmp = "TABuss";
        String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        HttpGet httpget = new HttpGet("http://vm-6114.idi.ntnu.no:1337/SpeechServer/cbrGuess?lat=" + lat
                + "&lon=" + lon + "&devID=" + tmp + p_id);
        long first = System.nanoTime();
        response = EntityUtils.toString(client.execute(httpget).getEntity(), "UTF-8");
        calc = new Calculate();
        System.out.println("RESPONSE: " + response);
        answ = calc.createCBRAnswer(response);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return answ;

}

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

private JSONObject getDeviceinfo() {
    JSONObject device = new JSONObject();
    try {/*from ww  w.ja  v  a  2 s .  c om*/
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String token = telephonyManager.getDeviceId().toString();
        device.put("notification_token", token);
        device.put("user_agent", System.getProperty("http.agent").toString());
    } catch (JSONException e) {
        Log.e("Json error", e.getMessage());
    }
    return device;
}

From source file:org.ubicompforall.BusTUC.Speech.HTTP.java

public DummyObj sendPost(String filePath, Context context, double lat, double lon) {
    String response = "Fant ikke noe";
    long first = System.nanoTime();
    Calc calc = new Calc();
    DummyObj dummy = new DummyObj();
    HttpClient httpclient = new DefaultHttpClient();
    long second = System.nanoTime() - first;
    //   File file = new File(Environment.getExternalStorageDirectory(),
    //      filePath);
    File file = new File(filePath);
    HttpPost httppost = new HttpPost("http://vm-6114.idi.ntnu.no:1337/SpeechServer/sst");
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String t_id = tm.getDeviceId();
    String tmp = "TABuss";
    String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    try {//from   w w  w.  j  ava  2  s  .co m
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("lat", new StringBody(String.valueOf(lat)));
        entity.addPart("lon", new StringBody(String.valueOf(lon)));
        entity.addPart("devID", new StringBody(tmp + p_id));
        entity.addPart("speechinput", new FileBody(file, "multipart/form-data;charset=\"UTF-8\""));

        httppost.setEntity(entity);
        response = EntityUtils.toString(httpclient.execute(httppost).getEntity(), "UTF-8");
        System.out.println("RESPONSE: " + response);
        dummy = calc.parse(response);
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }
    return dummy;

}

From source file:org.jssec.android.privacypolicynopreconfirm.MainActivity.java

public void onSendToServer(View view) {
    String nickname = ((TextView) findViewById(R.id.editTextNickname)).getText().toString();
    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    String imei = tm.getDeviceId();
    Toast.makeText(MainActivity.this,
            this.getClass().getSimpleName() + "\n - nickname : " + nickname + ", imei = " + imei,
            Toast.LENGTH_SHORT).show();/*from   w ww . ja va 2 s  .c  o  m*/
    new SendDataAsyncTack().execute(SEND_DATA_URI, UserId, nickname, imei);
}

From source file:com.bosco.noticeboard.RegistrationIntentService.java

/**
 * Persist registration to third-party servers.
 *
 * Modify this method to associate the user's GCM registration token with any server-side account
 * maintained by your application.//from   w  w w .ja  va2s.  c  om
 *
 * @param token The new token.
 */
private String sendRegistrationToServer(String token) {
    //TODO Sync channels from server to mobile after reinstalling app
    // get device IMEI number
    TelephonyManager mngr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String IMEI = "UNKNOWN";
    String deviceInfo = "UNKNOWN";
    try {
        IMEI = mngr.getDeviceId();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("SDK", Build.VERSION.SDK_INT);
        jsonObject.put("RELEASE", Build.VERSION.RELEASE);
        jsonObject.put("MODEL", android.os.Build.MODEL);
        jsonObject.put("BRAND", Build.BRAND);
        jsonObject.put("MANUFACTURER", Build.MANUFACTURER);
        Log.d(TAG, "DEVICE : " + jsonObject.toString());
        deviceInfo = jsonObject.toString();
    } catch (Exception e) {
        Log.d(TAG, "Unable to device info");
    }

    String url = NoticeBoardPreferences.URL_REGISTER_TOKEN;
    Map<String, String> payload = new HashMap<String, String>();
    payload.put(NoticeBoardPreferences.KEY_TOKEN, token);
    payload.put(NoticeBoardPreferences.KEY_IMEI, IMEI);
    payload.put(NoticeBoardPreferences.KEY_DEVICE, deviceInfo);

    NetworkHandler nh = new NetworkHandler(payload, url);
    return nh.callServer();

}

From source file:es.mdelapenya.uned.master.is.ubicomp.sensors.activities.location.BaseGeoLocatedActivity.java

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

    final String deviceId = telephonyManager.getDeviceId();
    final String simSerialNumber = telephonyManager.getSimSerialNumber();
    final String androidId = android.provider.Settings.Secure.getString(getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(),
            ((long) deviceId.hashCode() << 32) | simSerialNumber.hashCode());

    return deviceUuid.toString();
}

From source file:com.app.sniffy.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    settings = getSharedPreferences(PREFS_NAME, 0);
    storedKey = settings.getString("key", null);
    userConsent = settings.getBoolean("userconsent", false);
    context = this;

    // getting device id like IMEI no.
    TelephonyManager tMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mDeviceId = tMgr.getDeviceId();

    if (userConsent == false) {
        showTerms();//from  w w w . j a va 2 s.  c o  m
    } else if (storedKey == null) {

        try {
            new GetKey(this).execute(new URI(Utils.getConfigProperty(getResources(), "generate-key") + mDeviceId
                    + Utils.getConfigProperty(getResources(), "securekey")));
        } catch (URISyntaxException e1) {
            Log.d("main activity key generate", e1.toString());
        }
    }

}

From source file:bg.phpgcm2.RegistrationIntentService.java

/**
 * Persist registration to third-party servers.
 *
 * Modify this method to associate the user's GCM registration token with any server-side account
 * maintained by your application./*  w  w  w . j ava  2  s.c o m*/
 *
 * @param token The new token.
 */
private void sendRegistrationToServer(String token) {
    // TODO: Implement this method to send any registration to your app's servers.
    Log.i(TAG, "registering device (token = " + token + ")");
    String serverUrl = "https://www.smclinic.bg/conn/authorize.php";
    Map<String, String> params = new HashMap<String, String>();
    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    String deviceid = tm.getDeviceId();
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    ;
    if (!(model.startsWith(manufacturer))) {
        model = manufacturer + " " + model;
    }
    String serialno = Build.SERIAL;
    String osversion = Build.VERSION.RELEASE;
    SharedPreferences spsettings = getSharedPreferences("Motolife", MODE_PRIVATE);
    SharedPreferences.Editor speditor = spsettings.edit();

    params.put("fb", deviceid);
    speditor.putString("fb", deviceid);
    params.put("token", token);
    speditor.putString("token", token);
    params.put("fbname", "FB_name");
    speditor.putString("fbname", "FB_name");
    params.put("fbemail", "FB email");
    speditor.putString("fbemail", "FB_email");
    params.put("name", "name");
    speditor.putString("name", "name");
    params.put("email", "email");
    speditor.putString("email", "email");
    params.put("phone", "");
    speditor.putString("phone", "");
    params.put("bdate", "19770425");
    speditor.putString("bdate", "19770425");
    params.put("imei", deviceid);
    speditor.putString("imei", deviceid);
    params.put("serial", serialno);
    speditor.putString("serial", serialno);
    params.put("model", model);
    speditor.putString("model", model);
    params.put("osversion", osversion);
    speditor.putString("osversion", osversion);
    params.put("meters", "25");
    speditor.putString("meters", "25");
    params.put("xcoord", "0.123456");
    speditor.putString("xcoord", Double.toString(0.123456));
    params.put("ycoord", "0.123456");
    speditor.putString("ycoord", Double.toString(0.123456));
    params.put("version", "0.1");
    speditor.putString("version", "0.1");
    params.put("in", "0");
    speditor.putString("in", "0");
    params.put("platform", "0");
    params.put("sh", "0");
    speditor.putString("sh", "0");
    speditor.commit();
    try {
        post(serverUrl, params);
    } catch (IOException e) {
        Log.e(TAG, "Failed to register on attempt " + e);
    }
    Log.i(TAG, "registered");
}