Example usage for android.os Build SERIAL

List of usage examples for android.os Build SERIAL

Introduction

In this page you can find the example usage for android.os Build SERIAL.

Prototype

String SERIAL

To view the source code for android.os Build SERIAL.

Click Source Link

Document

A hardware serial number, if available.

Usage

From source file:com.silentcircle.silenttext.util.DeviceUtils.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static String getSerialNumber() {
    return android.os.Build.SERIAL;
}

From source file:com.aware.Aware.java

private void get_device_info() {
    Cursor awareContextDevice = awareContext.getContentResolver().query(Aware_Device.CONTENT_URI, null, null,
            null, null);//from   w  w w. j a  v  a 2s.c o  m
    if (awareContextDevice == null || !awareContextDevice.moveToFirst()) {
        ContentValues rowData = new ContentValues();
        rowData.put("timestamp", System.currentTimeMillis());
        rowData.put("device_id", Aware.getSetting(awareContext, Aware_Preferences.DEVICE_ID));
        rowData.put("board", Build.BOARD);
        rowData.put("brand", Build.BRAND);
        rowData.put("device", Build.DEVICE);
        rowData.put("build_id", Build.DISPLAY);
        rowData.put("hardware", Build.HARDWARE);
        rowData.put("manufacturer", Build.MANUFACTURER);
        rowData.put("model", Build.MODEL);
        rowData.put("product", Build.PRODUCT);
        rowData.put("serial", Build.SERIAL);
        rowData.put("release", Build.VERSION.RELEASE);
        rowData.put("release_type", Build.TYPE);
        rowData.put("sdk", Build.VERSION.SDK_INT);

        try {
            awareContext.getContentResolver().insert(Aware_Device.CONTENT_URI, rowData);

            Intent deviceData = new Intent(ACTION_AWARE_DEVICE_INFORMATION);
            sendBroadcast(deviceData);

            if (Aware.DEBUG)
                Log.d(TAG, "Device information:" + rowData.toString());

        } catch (SQLiteException e) {
            if (Aware.DEBUG)
                Log.d(TAG, e.getMessage());
        } catch (SQLException e) {
            if (Aware.DEBUG)
                Log.d(TAG, e.getMessage());
        }
    }
    if (awareContextDevice != null && !awareContextDevice.isClosed())
        awareContextDevice.close();
}

From source file:nl.nikhef.eduroam.WiFiEduroam.java

private void postData(String username, String password, String csr) throws RuntimeException {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(CONF_HTTP_URL);

    String android_id = Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID);

    try {//  w  w w  . ja va  2 s.  c o  m
        // Add the post data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username", username));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        nameValuePairs.add(new BasicNameValuePair("csr", csr));
        nameValuePairs.add(new BasicNameValuePair("device_id", android_id));
        nameValuePairs.add(new BasicNameValuePair("device_serial", android.os.Build.SERIAL));
        nameValuePairs.add(new BasicNameValuePair("device_description", android.os.Build.MANUFACTURER + " "
                + android.os.Build.MODEL + " / " + android.os.Build.PRODUCT));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP POST request synchronously
        HttpResponse response = httpclient.execute(httppost);
        if (!response.getStatusLine().toString().endsWith("200 OK")) {
            updateStatus("HTTP Error: " + response.getStatusLine());
        }

        // Convert input to JSON object
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        StringBuilder builder = new StringBuilder();
        for (String line = null; (line = reader.readLine()) != null;) {
            builder.append(line).append("\n");
        }
        String json = builder.toString();
        JSONObject obj = new JSONObject(json);

        if (!obj.getString("status").equals("ok")) {
            updateStatus("JSON Status Error: " + obj.getString("error"));
            throw new RuntimeException(obj.getString("error"));
        }
        // Grab the information
        certificate = obj.getString("certificate");
        ca = obj.getString("ca");
        ca_name = obj.getString("ca_name");
        realm = obj.getString("realm");
        subject_match = obj.getString("subject_match");
        ssid = obj.getString("ssid");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        throw new RuntimeException("Please check your connection!");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        throw new RuntimeException("JSON: " + e.getMessage());
    }
}

From source file:ru.dublgis.androidhelpers.DesktopUtils.java

public static String getBuildSerial() {
    try {//from  w w  w .jav a  2  s.  c o m
        if (Build.VERSION.SDK_INT >= 9) {
            return Build.SERIAL;
        }
    } catch (final Throwable e) {
        Log.e(TAG, "getBuildSerial exception: ", e);
    }
    return "";
}

From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java

public static String getHWID(Context cx) {
    if (sHWID != null)
        return sHWID;

    // If we're on SDK version > 8, use Build.SERIAL
    if (android.os.Build.VERSION.SDK_INT > 8) {
        sHWID = android.os.Build.SERIAL;
    }//from w  w w .  ja  v  a2s  .  co  m

    if (sHWID != null)
        return sHWID;

    // Otherwise, try from the telephony manager
    TelephonyManager mTelephonyMgr = (TelephonyManager) cx.getSystemService(TELEPHONY_SERVICE);
    if (mTelephonyMgr != null) {
        sHWID = mTelephonyMgr.getDeviceId();
    }

    if (sHWID != null)
        return sHWID;

    // Otherwise, try WIFI_SERVICE and use the wifi manager
    WifiManager wifiMan = (WifiManager) cx.getSystemService(Context.WIFI_SERVICE);
    if (wifiMan != null) {
        WifiInfo wifi = wifiMan.getConnectionInfo();
        if (wifi != null) {
            sHWID = "wifimac" + wifi.getMacAddress();
        }
    }

    if (sHWID != null)
        return sHWID;

    sHWID = "0011223344556677";

    return sHWID;
}

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

public void InformatonAndStatusCheck() {

    StringBuilder sb = new StringBuilder("");
    boolean hasFailInfo = false;

    if (mTelephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
        sb.append("getPhoneType:" + Integer.toString(mTelephonyManager.getPhoneType()) + "\n");
    } else {/*from   www  .  j  a  v  a 2 s  .c  o m*/
        sb.append("getPhoneType:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
        sb.append("getNetworkType:" + Integer.toString(mTelephonyManager.getNetworkType()) + "\n");
    } else {
        sb.append("getNetworkType:" + "fail");
        hasFailInfo = true;
    }

    String operatorName = mTelephonyManager.getNetworkOperatorName();
    if (operatorName != null && !operatorName.equals("")) { // OperatorName
        sb.append("getNetworkOperatorName:" + mTelephonyManager.getNetworkOperatorName() + "\n");
    } else {
        sb.append("getNetworkOperatorName:" + "fail");
        hasFailInfo = true;
    }

    String serial = Build.SERIAL;
    if (serial != null && !serial.equals("")) { // SerialNumber
        sb.append("get Serial Number:" + serial + "\n");
    } else {
        sb.append("get Serial Number:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN) {
        sb.append("getSimState:" + Integer.toString(mTelephonyManager.getSimState()) + "\n");
    } else {
        sb.append("getSimState:" + "fail");
        hasFailInfo = true;
    }

    //It's all ok
    sb.append("isNetworkRoaming:" + Boolean.toString(mTelephonyManager.isNetworkRoaming()) + "\n");

    if (mTelephonyManager.getDataState() != TelephonyManager.DATA_DISCONNECTED) {
        sb.append("getDataState:" + Integer.toString(mTelephonyManager.getDataState()) + "\n");
    } else {
        sb.append("getDataState:" + "fail");
        hasFailInfo = true;
    }

    String formatIP = formatIpAddresses(mLinkProperties);
    if (formatIP != null && !formatIP.equals("")) { //IP Address
        sb.append("IP Address:" + formatIpAddresses(mLinkProperties) + "\n");
    } else {
        sb.append("IP Address:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
        if (checkGsmDeviceId(mTelephonyManager.getDeviceId())) {
            sb.append("IMEI:" + mTelephonyManager.getDeviceId() + "\n");
        } else {
            sb.append("IMEI:" + "fail");
            hasFailInfo = true;
        }
    } else {
        sb.append("IMEI:" + "fail");
        hasFailInfo = true;
    }

    Log.i(tag, sb.toString());

    mLog = sb.toString();
    if (!hasFailInfo) {
        Log.i(tag, "test_5th_InformatonAndStatus true");
        outputResult(true, tTelephonyBasicFunc, dBasicInformation, testCaseId);
    } else {
        Log.i(tag, "test_5th_InformatonAndStatus false");
        outputResult(false, tTelephonyBasicFunc, dBasicInformation, testCaseId);
    }

    //Log.i(tag, "getPhoneType:" + Integer.toString(mTelephonyManager.getPhoneType()));
    //Log.i(tag, "getNetworkType:" + Integer.toString(mTelephonyManager.getNetworkType()));
    //Log.i(tag, "getNetworkOperatorName:" + mTelephonyManager.getNetworkOperatorName());
    //Log.i(tag, "getSimSerialNumber:" + mTelephonyManager.getSimSerialNumber());
    //Log.i(tag, "getSimState:" + Integer.toString(mTelephonyManager.getSimState()));
    //Log.i(tag, "isNetworkRoaming:" + Boolean.toString(mTelephonyManager.isNetworkRoaming()));
    //Log.i(tag, "getDataState:" + Integer.toString(mTelephonyManager.getDataState()));   
    //Log.i(tag,"formatIpAddresses(mLinkProperties): " + formatIpAddresses(mLinkProperties));

}

From source file:com.droid.app.fotobot.FotoBot.java

/**
 *   ?  ? ? /*from   w  w w .ja va 2  s .c o m*/
 *
 * @param h
 * @param str
 */
public void SendMail(Handler h, String str, String fc_str, String bc_video, String fc_video) {

    //        final FotoBot fb = (FotoBot) getApplicationContext();

    Mail m = new Mail(getApplicationContext(), EMail_Sender, EMail_Sender_Password, SMTP_Host, SMTP_Port);

    String[] toArr = { EMail_Recepient };

    String s = "Debug-infos:";
    s += "\n OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL
            + ")";
    s += "\n OS API Level: " + android.os.Build.VERSION.SDK_INT;
    s += "\n Device: " + android.os.Build.DEVICE;
    s += "\n Model (and Product): " + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")";

    s += "\n RELEASE: " + android.os.Build.VERSION.RELEASE;
    s += "\n BRAND: " + android.os.Build.BRAND;
    s += "\n DISPLAY: " + android.os.Build.DISPLAY;
    s += "\n CPU_ABI: " + android.os.Build.CPU_ABI;
    s += "\n CPU_ABI2: " + android.os.Build.CPU_ABI2;
    s += "\n UNKNOWN: " + android.os.Build.UNKNOWN;
    s += "\n HARDWARE: " + android.os.Build.HARDWARE;
    s += "\n Build ID: " + android.os.Build.ID;
    s += "\n MANUFACTURER: " + android.os.Build.MANUFACTURER;
    s += "\n SERIAL: " + android.os.Build.SERIAL;
    s += "\n USER: " + android.os.Build.USER;
    s += "\n HOST: " + android.os.Build.HOST;

    m.setTo(toArr);
    m.setFrom(EMail_Sender);
    m.setSubject("Fotobot v" + versionName + " " + Camera_Name);

    String email_body = "";

    email_body = "Fotobot v" + versionName + "\n" + "---------------------------------------------\n"
            + "Camera Name" + ": " + Camera_Name + "\n" + getResources().getString(R.string.battery_charge)
            + ": " + battery_level + "%" + "\n" + getResources().getString(R.string.battery_temperature) + ": "
            + battery_temperature + "C" + "\n";

    if (Attached_Info_Detailisation.equals("Normal") || Attached_Info_Detailisation.equals("Detailed")) {

        email_body = email_body + getResources().getString(R.string.gsm) + ": " + GSM_Signal + "ASU    "
                + (2.0 * GSM_Signal - 113) + "dBm" + "\n" + "-50 -82 dbm   -   very good" + "\n"
                + "-83 -86 dbm   -   good" + "\n" + "-87 -91 dbm   -   normal" + "\n" + "-92 -95 dbm   -   bad"
                + "\n" + "-96 -100 dbm   -  almost no signal" + "\n"
                + "---------------------------------------------\n" + "Image Index:" + Image_Index + "\n"
                + "---------------------------------------------\n"
                + getResources().getString(R.string.phone_memory) + ":" + "\n" + "totalMemory: " + totalMemory
                + "\n" + "usedMemory: " + usedMemory + "\n" + "freeMemory: " + freeMemory + "\n"
                + "---------------------------------------------\n"
                + getResources().getString(R.string.email_sending_time) + ": " + email_sending_time + "\n"
                + "---------------------------------------------\n"
                + getResources().getString(R.string.Fotobot_settings) + ":\n" + "Network_Channel: "
                + Network_Channel + "\n" + "Network_Connection_Method: " + Network_Connection_Method + "\n"
                + "Use_Flash: " + Use_Flash + "\n" + "JPEG_Compression: " + JPEG_Compression + "\n"
                + "Photo_Frequency: " + Photo_Frequency + "\n" + "process_delay: " + process_delay + "\n"
                + "Image_Scale: " + Image_Scale + "\n" + "Image_Size: " + Image_Size + "\n" + "EMail_Sender: "
                + EMail_Sender + "\n" + "EMail_Sender_Password: *********" + "\n" + "EMail_Recepient: "
                + EMail_Recepient + "\n" + "Log_Font_Size: " + Log_Font_Size + "\n" + "Config_Font_Size: "
                + Config_Font_Size + "\n" + "Photo_Post_Processing_Method: " + Photo_Post_Processing_Method
                + "\n" + "SMTP_Host: " + SMTP_Host + "\n" + "SMTP_Port: " + SMTP_Port + "\n" + "Log length: "
                + loglength + "\n" + "FLog length: " + floglength + "\n" + "wake_up_interval: "
                + wake_up_interval + "\n" + "---------------------------------------------\n"
                + getResources().getString(R.string.hardware_info) + ":\n" + "Android: " + Build.VERSION.SDK_INT
                + "\n" + s + "\n" + "---------------------------------------------\n"
                + "Available SMS commands: " + "\n" + sms_commands_list() + "\n";
        ;
        if (Attached_Info_Detailisation.equals("Detailed")) {
            email_body = email_body + "\n\n\nActive tasks:\n" + Top + "\n\n\nBack Camera Properties:\n"
                    + Camera_Properties + "\n\n\nFront Camera Properties:\n" + fc_Camera_Properties;
        }

    }

    m.setBody(email_body);

    File attach_file;

    if (make_photo_bc && bc_image_attach) {

        attach_file = new File(str);
        boolean fileExists = attach_file.isFile();

        if (fileExists) {

        } else {
            SendMessage("ERROR: image doesn't exist for attaching to email.", MSG_FAIL);
        }
    }

    if (make_video_bc && bc_video_attach) {

        attach_file = new File(bc_video);
        boolean fileExists = attach_file.isFile();

        if (fileExists) {

        } else {
            SendMessage("ERROR: video " + bc_video + " doesn't exist for attaching to email.", MSG_FAIL);
        }
    }

    if (front_camera && make_photo_fc && fc_image_attach) {

        attach_file = new File(fc_str);
        boolean fc_fileExists = attach_file.isFile();

        if (front_camera && fc_fileExists && make_photo_fc) {

        } else {
            SendMessage("ERROR: front camera image doesn't exist for attaching to email.", MSG_FAIL);
        }
    }

    if (front_camera && make_video_fc && fc_video_attach) {

        attach_file = new File(fc_video);
        boolean fc_fileExists = attach_file.isFile();

        if (front_camera && fc_fileExists && make_photo_fc) {

        } else {
            SendMessage("ERROR: video " + fc_video + " doesn't exist for attaching to email.", MSG_FAIL);
        }
    }

    if (attach_log) {
        attach_file = new File((work_dir + "/logfile.txt"));
        boolean fileExists = attach_file.isFile();

        if (fileExists) {

        } else {
            SendMessage("ERROR: log doesn't exist for attaching to email.", MSG_FAIL);
        }

    }
    try {

        if (make_photo_bc && bc_image_attach) {
            m.addAttachment(str);
        }

        if (front_camera && make_photo_fc && fc_image_attach) {
            m.addAttachment(fc_str);
        }

        if (make_video_bc && bc_image_attach) {
            m.addAttachment(bc_video);
        }

        if (front_camera && make_video_fc && fc_image_attach) {
            m.addAttachment(fc_video);
        }

        if (attach_log) {
            m.addAttachment(work_dir + "/logfile.txt");
        }
        fbpause(h, process_delay);

        if (m.send()) {

            SendMessage(getResources().getString(R.string.foto_sent), MSG_PASS);

            SaveSettings();

        } else {
            SendMessage("ERROR: ?   ", MSG_FAIL);
        }
    } catch (Exception e) {
        SendMessage("Could not send email", MSG_FAIL);
        Log.e("MailApp", "Could not send email", e);
    }

}

From source file:com.vegnab.vegnab.MainVNActivity.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public void getUniqueDeviceId(Context context) {
    // this is used to get a unique identifier for the device this app is being run on
    // it is primarily used to warn the user if the Visit has been downloaded onto
    // a different device and the Visit is about to be edited;
    // This simple fn is not entirely robust for various reasons, but it is adequate since
    // it is rare for Visits to be edited, and even more rare to be downloaded before editing
    // this ID may be useful in sorting out field work chaos, to tell where the data came from
    String deviceId;/*from w  ww. ja  v a 2  s. c  o m*/
    try {
        TelephonyManager tMgr = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
        deviceId = tMgr.getDeviceId();
        if (deviceId != null) { // won't have this if device is not a phone, and
                                //not always reliable to read even if it is a phone
            mDeviceIdSource = "Phone";
            mUniqueDeviceId = deviceId;
            return;
        } else { // try to get the Android ID
            deviceId = android.os.Build.SERIAL; // generated on first boot, so may change on system reset
            // only guaranteed available from API 9 and up
            // since Gingerbread (Android 2.3) android.os.Build.SERIAL must exist on any device that doesn't provide IMEI
            if (deviceId != null) {
                // some Froyo 2.2 builds give the same serial number "9774d56d682e549c" for
                // all, but these are rare and dying out (fixed ~December 2010.
                // 4.2+, different profiles on the same device may give different IDs
                mDeviceIdSource = "Android serial number";
                mUniqueDeviceId = deviceId;
                return;
            } else {
                // generate a random number
                mDeviceIdSource = "random UUID";
                mUniqueDeviceId = UUID.randomUUID().toString();
                return;
            }
        }
    } catch (Exception e) {
        // generate a random number
        mDeviceIdSource = "random UUID";
        mUniqueDeviceId = UUID.randomUUID().toString();
        return;
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Generates a unique device id using the device 
 * "serial" property if is available. If not, a bunch
 * of device properties will be used to get a reliable
 * unique string key for the device.//from  www .  j  a v  a  2  s  .c  o  m
 * 
 * If there is an error in UUID generation null is
 * returned.
 *    
 * @return   The unique UUID or nul in case of error.
 */
private static UUID generateUniqueDeviceUUIDId() {
    UUID uuid = null;

    try {
        //We generate a unique id
        String serial = null;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
            serial = Build.SERIAL;
            uuid = UUID.nameUUIDFromBytes(serial.getBytes("utf8"));
        } else {
            //This bunch of data should be enough to "ensure" the 
            //uniqueness.
            String m_szDevIDAlterbative = "35" + //To look like a valid IMEI
                    Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10
                    + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
                    + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10
                    + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
                    + Build.USER.length() % 10; //13 digits

            uuid = UUID.nameUUIDFromBytes(m_szDevIDAlterbative.getBytes("utf8"));
        }

    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "UnsupportedEncodingException (" + e.getMessage() + ").", e);
    }

    return uuid;
}