get Model - Android Android OS

Android examples for Android OS:System Model

Description

get Model

Demo Code


//package com.java2s;

import android.os.Build;

import android.text.TextUtils;

public class Main {
    public static String getModel() {
        return getDeviceModel();
    }/*from  w  w w .  jav a2 s.  com*/

    private static String getDeviceModel() {
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
        String deviceMode;
        if (model.startsWith(manufacturer)) {
            deviceMode = metaDeviceModel(model);
        } else {
            deviceMode = metaDeviceModel(manufacturer) + " " + model;
        }
        return deviceMode;
    }

    private static String metaDeviceModel(String string) {
        if (TextUtils.isEmpty(string)) {
            return "";
        }

        char first = string.charAt(0);
        if (Character.isUpperCase(first)) {
            return string;
        } else {
            if (string.length() > 1) {
                return Character.toUpperCase(first) + string.substring(1);
            } else {
                return string;
            }
        }
    }
}

Related Tutorials