get capitalized Device Model - Android Hardware

Android examples for Hardware:Device Feature

Description

get capitalized Device Model

Demo Code


//package com.java2s;

import android.os.Build;

public class Main {
    public static String getDeviceModel() {
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
        if (model.startsWith(manufacturer)) {
            return capitalize(model);
        } else {//from w  w w .  j  a  v a  2 s .c om
            return capitalize(manufacturer) + " " + model;
        }
    }

    private static String capitalize(String s) {
        if (s == null || s.length() == 0) {
            return "";
        }
        char first = s.charAt(0);
        if (Character.isUpperCase(first)) {
            return s;
        } else {
            return Character.toUpperCase(first) + s.substring(1);
        }
    }
}

Related Tutorials