get Device Model - Android Hardware

Android examples for Hardware:Device Feature

Description

get Device Model

Demo Code


//package com.java2s;

import android.os.Build;

import android.text.TextUtils;

public class Main {
    private static String getDeviceModel() {
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
        String deviceMode;//from www. j  a v  a  2  s.c  o  m
        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