Coder Social home page Coder Social logo

morristech / androiddevicenames Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tslamic/androiddevicenames

0.0 1.0 0.0 383 KB

A tiny Android library that transforms the device model name into something users can understand.

Java 21.18% Kotlin 78.82%

androiddevicenames's Introduction

Android Device Names v2 Build Status

This tiny Android library transforms a device model name into something people can understand. For example, a useless SM-N910W8 becomes Samsung Galaxy Note4 with a single method call. ๐ŸŽ‰

To use it, add the following to your list of dependencies:

compile 'com.github.tslamic:dn2:1.1'

If you only want to extract the current device name, or perform a single query, DeviceNames is what you're after:

DeviceNames names = AndroidDeviceNames.deviceNames(context);
String device = names.currentDeviceName();

For multiple queries, DeviceNamesDatabase will perform better. Since you have to explicitly open and close it, it's probably best to make it follow a lifecycle, e.g.:

private DeviceNamesDatabase database;

@Override protected void onCreate(Bundle savedInstanceState) {
  // ...
  database = AndroidDeviceNames.deviceNamesDatabase(this);
}

@Override protected void onStart() {
  super.onStart();
  database.open();
}

@Override protected void onStop() {
  super.onStop();
  database.close();
}

String query(@NonNull String model) {
  return database.deviceName(model, "UNKNOWN");
}

Both DeviceNames and DeviceNamesDatabase offer three methods:

method description
currentDeviceName() Returns a user-friendly current device name, or null if the model is unknown.
currentDeviceName(String fallback) Same as above, but returns fallback if the model is unknown.
deviceName(String model, String fallback) Returns a user-friendly name for the specified model, or fallback, if the model is unknown.

The library recognizes all Google Play supported devices, which is currently a bit less than 13k devices.

Not backwards compatible with v1

If you've been using AndroidDeviceNames v1, please note that v2 is not backwards compatible. Updating should be trivial and result in minimal code change though.

License

Copyright 2017 Tadej Slamic

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

androiddevicenames's People

Contributors

tslamic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.