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.general.vvvv.cmr.MySplash.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    dbLogin = new DbLogin(MySplash.this, DbLogin.DB_NAME, null, DbLogin.DB_VERSION);
    db_read = dbLogin.getReadableDatabase();
    db_write = dbLogin.getWritableDatabase();

    String identifier = null;/*from w w  w  . ja v a2 s .c  om*/
    TelephonyManager tm = (TelephonyManager) this.getSystemService(this.TELEPHONY_SERVICE);
    if (tm != null) {
        identifier = tm.getDeviceId();
    }
    if (identifier == null || identifier.length() == 0) {
        identifier = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
    }
    Toast.makeText(MySplash.this, "Your IMEI no:" + identifier, Toast.LENGTH_LONG).show();

    System.out.println("IMEI no:" + identifier);
    Log.d("IMEI or Android id:", identifier);

    Cursor cursor = dbLogin.getData(db_read);
    if (cursor.getCount() > 0) {
        Intent intent = new Intent(MySplash.this, MyLogin.class);
        startActivity(intent);
    } else {
        Toast.makeText(MySplash.this, "Login database is empty", Toast.LENGTH_SHORT).show();
        if (identifier != null) {
            new AsynchLogin().execute(identifier);
        } else {
            Toast.makeText(MySplash.this, "Unable to find your IMEI no.", Toast.LENGTH_LONG).show();
        }

    }
}

From source file:com.toppatch.mv.ui.activities.LoginActivity2.java

@SuppressWarnings("unchecked")
private void startLoginCheck() {
    Log.d(TAG, "startLoginCheck");
    CheckLoginAsyncTask check = new CheckLoginAsyncTask();
    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(Constants.LOGIN_ACTIVITY_EMAIL, email.getText().toString()));
    params.add(new BasicNameValuePair(Constants.LOGIN_ACTIVITY_PASSCODE, passcode.getText().toString()));
    params.add(new BasicNameValuePair(Constants.LOGIN_ACTIVITY_GCM, gcmId));
    TelephonyManager mngr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    params.add(new BasicNameValuePair(Constants.IMEI, mngr.getDeviceId()));
    Log.d("see", "sss:" + gcmId);
    check.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}

From source file:com.vkassin.mtrade.CSPLicense.java

boolean getLicense() {

    HttpClient httpclient = getNewHttpClient();
    HttpPost httppost = new HttpPost(licenseURL); //licenseURL - url   ,  (https://shop.gamma.kz/gs_cart/get_mobile_license) 
    try {//from   w w  w  . jav a2s .  c  om

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("os", "android"));
        TelephonyManager telephonyManager = (TelephonyManager) Common.app_ctx
                .getSystemService(Context.TELEPHONY_SERVICE);
        nameValuePairs.add(new BasicNameValuePair("imei", telephonyManager.getDeviceId()));
        nameValuePairs.add(new BasicNameValuePair("code", getLicenseCode())); //     ,   
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = EntityUtils.toString(entity); //  result   
            Log.i(TAG, "license = " + result);
            //         boolean b = this.installLicense(result);
            //         Log.i(TAG, "write to file = " + b);

        } else
            return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.fallahpoor.infocenter.fragments.GeneralFragment.java

private String getDeviceID() {

    TelephonyManager telMgr = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    String deviceID = null;/*www.  ja v a  2  s .c om*/

    if (telMgr != null) {
        deviceID = telMgr.getDeviceId();
    }

    if (Utils.isEmpty(deviceID)) {
        deviceID = getString(R.string.unknown);
    }

    return deviceID;

}

From source file:au.com.websitemasters.schools.lcps.push.RegistrationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {// w w  w .  j av a 2  s.c  om
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
        // See https://developers.google.com/cloud-messaging/android/start for details on this file.
        // [START get_token]

        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

        String uid;
        try {
            uid = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        } catch (NullPointerException e) {
            final TelephonyManager tm = (TelephonyManager) getBaseContext()
                    .getSystemService(Context.TELEPHONY_SERVICE);
            final String tmDevice, tmSerial, androidId;
            tmDevice = "" + tm.getDeviceId();
            tmSerial = "" + tm.getSimSerialNumber();
            androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(),
                    android.provider.Settings.Secure.ANDROID_ID);
            UUID deviceUuid = new UUID(androidId.hashCode(),
                    ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
            uid = deviceUuid.toString();
        }

        Log.d("rklogs", "uid: " + uid);
        Log.d("rklogs", "GCM Reg Token: " + token);

        RetrofitClient client = new RetrofitClient();
        client.postToken(token, uid);

        // [END get_token]
        // TODO: Implement this method to send any registration to your app's servers.
        sendRegistrationToServer(token);

        // Subscribe to topic channels
        subscribeTopics(token);

        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(getResources().getString(R.string.sent_token_to_server), true)
                .apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(getResources().getString(R.string.sent_token_to_server), false)
                .apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(getResources().getString(R.string.registration_complete));
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

From source file:wfa.com.tma.wfa.main.MainActivity.java

private void cancerAlarm() {
    mydb.deleteAlarmStatus();/* w ww  .j  a  v  a  2  s . com*/
    mydb.insertDuressStatus(DuressStatus.NORMAL.toString());
    TelephonyManager mngr = (TelephonyManager) MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = mngr.getDeviceId();
    Double latitude = Utils.gpsTracker.canGetLocation() ? Utils.gpsTracker.getLatitude() : 0;
    Double longtitude = Utils.gpsTracker.canGetLocation() ? Utils.gpsTracker.getLongitude() : 0;
    Long time = System.currentTimeMillis();
    int hash = 2;
    String message = "TMA5," + imei + "," + time + "," + latitude + "," + longtitude + "," + hash;
    String md5 = Utils.calcMD5(message);
    message = message + "," + md5;
    Toast.makeText(getApplicationContext(), "Cancel Alarm", Toast.LENGTH_SHORT).show();
    UdpGateway.getInstance().send(mydb.getServerIP(), Integer.parseInt(mydb.getServerUdpPort()), message);
}

From source file:wfa.com.tma.wfa.main.MainActivity.java

private void acknowledge() {
    mydb.deleteAlarmStatus();//  w  ww. java 2 s . c  o  m
    mydb.insertDuressStatus(DuressStatus.NORMAL.toString());
    TelephonyManager mngr = (TelephonyManager) MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = mngr.getDeviceId();
    Double latitude = Utils.gpsTracker.canGetLocation() ? Utils.gpsTracker.getLatitude() : 0;
    Double longtitude = Utils.gpsTracker.canGetLocation() ? Utils.gpsTracker.getLongitude() : 0;
    Long time = System.currentTimeMillis();
    int hash = 2;
    String message = "TMA5," + imei + "," + time + "," + latitude + "," + longtitude + "," + hash;
    String md5 = Utils.calcMD5(message);
    message = message + "," + md5;
    Toast.makeText(getApplicationContext(), "Cancel Alarm", Toast.LENGTH_SHORT).show();
    UdpGateway.getInstance().send(mydb.getServerIP(), Integer.parseInt(mydb.getServerUdpPort()), message);
}

From source file:wfa.com.tma.wfa.main.MainActivity.java

private void alarmToServer() {
    MainActivity.this.mydb.deleteAlarmStatus();
    mydb.insertDuressStatus(DuressStatus.DURESS.toString());
    TelephonyManager mngr = (TelephonyManager) MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = mngr.getDeviceId();
    Double latitude = Utils.gpsTracker.canGetLocation() ? Utils.gpsTracker.getLatitude() : 0;
    Double longtitude = Utils.gpsTracker.canGetLocation() ? Utils.gpsTracker.getLongitude() : 0;
    Long time = System.currentTimeMillis();
    int hash = 2;
    String alarmType = "SOS";
    String message = "TMA4," + imei + "," + time + "," + alarmType + "," + latitude + "," + longtitude + ","
            + hash;// w w  w.  j ava2s.  c o  m
    String md5 = Utils.calcMD5(message);
    message = message + "," + md5;
    Toast.makeText(getApplicationContext(), "Alarm to server", Toast.LENGTH_SHORT).show();
    UdpGateway.getInstance().send(mydb.getServerIP(), Integer.parseInt(mydb.getServerUdpPort()), message);
}

From source file:emcewen.websms.services.C2DMRegistrationService.java

private void registerForPush(String regID, String username) {
    Log.d(TAG, "Register with WebApp!");
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://sms.evanmcewen.ca/devices");
    JSONObject json = new JSONObject();
    TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);

    try {//from ww  w.  jav a  2 s  . c  o m
        // Add your data
        json.put("username", username);
        json.put("reg_id", regID);
        json.put("device_id", telephonyManager.getDeviceId());
        json.put("nickname", "");
        StringEntity se = new StringEntity(json.toString());
        se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httppost.setEntity(se);

        // Execute HTTP Post Request
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = httpclient.execute(httppost, responseHandler);

        if (response != null) {
            Intent successIntent = new Intent(WebSMSActivity.PUSH_SUCCESS);
            super.sendBroadcast(successIntent);
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.ubicompforall.BusTUC.Queries.Browser.java

public String getRequestServer(String stop, Boolean formated, Location location, int numStops, int dist,
        Context context) {//w  w  w . j a  v a2s  . com
    String html_string = null;
    HttpGet m_get = new HttpGet();
    try {
        stop = URLEncoder.encode(stop, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // HttpPost m_post= new
    // HttpPost("http://m.atb.no/xmlhttprequest.php?service=routeplannerOracle.getOracleAnswer&question=");
    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);
        m_get.setURI(new URI("http://busstjener.idi.ntnu.no/MultiBRISserver/MBServlet?dest=" + stop + "&lat="
                + location.getLatitude() + "&long=" + location.getLongitude() + "&type=json&nStops=" + numStops
                + "&maxWalkDist=" + dist + "&key=" + tmp + p_id));
        HttpResponse m_response = m_client.execute(m_get);
        // Request
        html_string = httpF.requestServer(m_response);
        // Will fail if server is busy or down
        Log.v("html_string", "Returned html: " + html_string);
        // Long newTime = System.nanoTime() - time;
        // System.out.println("TIMEEEEEEEEEEEEEEEEEEEEE: " +
        // newTime/1000000000.0);
    } catch (ClientProtocolException e) {
        Log.v("CLIENTPROTOCOL EX", "e:" + e.toString());
    } catch (IOException e) {
        Log.v("IO EX", "e:" + e.toString());

    } catch (NullPointerException e) {
        Log.v("NULL", "NullPointer");
    } catch (StringIndexOutOfBoundsException e) {
        Log.v("StringIndexOutOfBounds", "Exception");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return html_string;
}