[Android Library] Get easy access to device information super fast, real quick

Overview

DeviceInfo-Sample

Android Arsenal

Simple, single class wrapper to get device information from an android device.

This library provides an easy way to access all the device information without having to deal with all the boilerplate stuff going on inside.

As part of the process of my learning kotlin, I migrated the library to support Kotlin as well. If you would like to view the Kotlin version of the library - please checkout branch migrate_to_kotlin

Library also provides option to ask permissions for Marshmellow devices!

Sample App

Get it on Google Play

Donwload the sample app on the Google Play Store and check out all the features

API

How to integrate the library in your app?

Gradle Dependecy
dependencies {
        implementation 'com.an.deviceinfo:deviceinfo:0.1.5'
}

Maven Dependecy

<dependency>
  <groupId>com.an.deviceinfo</groupId>
  <artifactId>deviceinfo</artifactId>
  <version>0.1.5</version>
  <type>pom</type>
</dependency>

Downloads

You can download the aar file from the release folder in this project.
In order to import a .aar library:
1) Go to File>New>New Module
2) Select "Import .JAR/.AAR Package" and click next.
3) Enter the path to .aar file and click finish.
4) Go to File>Project Settings (Ctrl+Shift+Alt+S).
5) Under "Modules," in left menu, select "app."
6) Go to "Dependencies tab.
7) Click the green "+" in the upper right corner.
8) Select "Module Dependency"
9) Select the new module from the list.

Usage

For easy use, I have split up all the device information by the following:
1. Location
2. Ads
3. App
4. Battery
5. Device
6. Memory
7. Network
8. User Installed Apps
9. User Contacts

Location

LocationInfo locationInfo = new LocationInfo(this);
DeviceLocation location = locationInfo.getLocation();
Value Function Name Returns
Latitude getLatitude() Double
Longitude getLongitude() Double
Address Line 1 getAddressLine1() String
City getCity() String
State getState() String
CountryCode getCountryCode() String
Postal Code getPostalCode() String

Ads

No Google play services needed!
AdInfo adInfo = new AdInfo(this);
adInfo.getAndroidAdId(new new AdInfo.AdIdCallback() {
                         @Override
                         public void onResponse(Ad ad) {
                             String advertisingId = ad.getAdvertisingId();
                             Boolean canTrackAds = ad.isAdDoNotTrack();
                         }
                     });
Value Function Name Returns
AdvertisingId getAdvertisingId() String
Can Track ads isAdDoNotTrack() boolean

App

App app = new App(this);
Value Function Name Returns
App Name getAppName() String
Package Name getPackageName() String
Activity Name getActivityName() String
App Version Name getAppVersionName() String
App Version Code getAppVersionCode() Integer

Battery

Battery battery = new Battery(this);
Value Function Name Returns
Battery Percent getBatteryPercent() int
Is Phone Charging isPhoneCharging() boolean
Battery Health getBatteryHealth() String
Battery Technology getBatteryTechnology() String
Battery Temperature getBatteryTemperature() float
Battery Voltage getBatteryVoltage() int
Charging Source getChargingSource() String
Is Battery Present isBatteryPresent() boolean

Device

Device device = new Device(this);
Value Function Name Returns
Release Build Version getReleaseBuildVersion() String
Build Version Code Name getBuildVersionCodeName() String
Manufacturer getManufacturer() String
Model getModel() String
Product getProduct() String
Fingerprint getFingerprint() String
Hardware getHardware() String
Radio Version getRadioVersion() String
Device getDevice() String
Board getBoard() String
Display Version getDisplayVersion() String
Build Brand getBuildBrand() String
Build Host getBuildHost() String
Build Time getBuildTime() long
Build User getBuildUser() String
Serial getSerial() String
Os Version getOsVersion() String
Language getLanguage() String
SDK Version getSdkVersion() int
Screen Density getScreenDensity() String
Screen Height getScreenHeight() int
Screen Density getScreenWidth() int

Memory

Memory memory = new Memory(this);
Value Function Name Returns
Has External SD Card isHasExternalSDCard() boolean
Total RAM getTotalRAM() long
Available Internal Memory Size getAvailableInternalMemorySize() long
Total Internal Memory Size getTotalInternalMemorySize() long
Available External Memory Size getAvailableExternalMemorySize() long
Total External Memory Size getTotalExternalMemorySize() String

Network

Network network = new Network(this);
Value Function Name Returns
IMEI getIMEI() String
IMSI getIMSI() String
Phone Type getPhoneType() String
Phone Number getPhoneNumber() String
Operator getOperator() String
SIM Serial getsIMSerial() String
Network Class getNetworkClass() String
Network Type getNetworkType() String
Is SIM Locked isSimNetworkLocked() boolean
Is Nfc Present isNfcPresent() boolean
Is Nfc Enabled isNfcEnabled() boolean
Is Wifi Enabled isWifiEnabled() boolean
Is Network Available isNetworkAvailable() boolean

User Installed Apps

UserAppInfo userAppInfo = new UserAppInfo(this);
List<UserApps> userApps = userAppInfo.getInstalledApps(boolean includeSystemApps);
Value Function Name Returns
App Name getAppName() String
Package Name getPackageName() String
Version Name getVersionName() String
Version Code getVersionCode() int

User Contacts

UserContactInfo userContactInfo = new UserContactInfo(mActivity);
List<UserContacts> userContacts = userContactInfo.getContacts();
Value Function Name Returns
Contact Name getDisplayName() String
Mobile Number getMobileNumber() String
Phone Type phoneType() String

How to get Permissions for android 6+

Easy! I have provided a small, easy wrapper for getting permissions for marshmellow devices.

First, override onRequestPermissionsResult and call PermissionManager.handleResult(requestCode, permissions, grantResults);

PermissionManager permissionManager = new PermissionManager(this);
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        permissionManager.handleResult(requestCode, permissions, grantResults);
    }

Now you can ask permission:

permissionManager.showPermissionDialog(permission)
                    .withDenyDialogEnabled(true)
                    .withDenyDialogMsg(mActivity.getString(R.string.permission_location))
                    .withCallback(new PermissionManager.PermissionCallback() {
                        @Override
                        public void onPermissionGranted(String[] permissions, int[] grantResults) {
                            //you can handle what to do when permission is granted
                        }

                        @Override
                        public void onPermissionDismissed(String permission) {
                           /**
                             * user has denied the permission. We can display a custom dialog 
                             * to user asking for permission
                           * */
                        }

                        @Override
                        public void onPositiveButtonClicked(DialogInterface dialog, int which) {
                          /**
                            * You can choose to open the
                            * app settings screen
                            * * */
                              PermissionUtils permissionUtils = new PermissionUtils(this);
                              permissionUtils.openAppSettings();
                        }

                        @Override
                        public void onNegativeButtonClicked(DialogInterface dialog, int which) {
                          /**
                            * The user has denied the permission!
                            * You need to handle this in your code
                            * * */
                        }
                    })
                    .build();

Various options available in PermissionManager

Value Function Name Returns
To enable custom dialog when user has denied the permission withDenyDialogEnabled() boolean
To enable Rationale, explaining the need for the permission, the first time they have denied the permission withRationaleEnabled() boolean
Message to be displayed in the custom dialog withDenyDialogMsg() String
Title to be displayed in the custom dialog withDenyDialogTitle() String
Postive Button text to be displayed in the custom alert dialog withDenyDialogPosBtnText() String
Negative Button text to be displayed in the custom alert dialog withDenyDialogNegBtnText() String
Should display the negative button flag withDenyDialogNegBtn() boolean
Flag to cancel the dialog isDialogCancellable() boolean

Created and maintained by:

Anitaa Murthy [email protected]

Twitter Google Plus Linkedin

You might also like...
DocuBox is a cloud based file storing app where you can securely store and access your documents from anywhere around the world
DocuBox is a cloud based file storing app where you can securely store and access your documents from anywhere around the world

DocuBox is an android app 📱in which you can securely upload your files on the cloud– from family pictures and audio recordings to spreadsheets, presentations and other confidential documents.

Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

The Superhero app keeps track of the near real-time location of all the volunteers.

Superhero The Superhero app keeps track of the near real-time location of all the volunteers. The app sends requests for emergency tasks to nearby vol

Example of migrating from Dagger to Hilt with a real service/repository example

DaggerToHilt Overview This repo provides a real example of using Hilt for dependency injection. It hits endpoints provided by the Movie Database, and

Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.
Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.

Clickstream is an event agnostic, real-time data ingestion platform. Clickstream allows apps to maintain a long-running connection to send data in real-time.

A fast, lightweight, entity component system library written in Kotlin.

Fleks A fast, lightweight, entity component system library written in Kotlin. Motivation When developing my hobby games using LibGDX, I always used As

REST countries sample app that loads information from REST countries API V3 to show an approach to using some of the best practices in Android Development.
REST countries sample app that loads information from REST countries API V3 to show an approach to using some of the best practices in Android Development.

MAJORITY assignment solution in Kotlin via MVVM Repository Pattern. REST countries sample app that loads information from REST countries API V3 to sho

RickAndMortyApp - Rick and morty, app about characters information
RickAndMortyApp - Rick and morty, app about characters information

Rick And Morty App 🇧🇷 Aplicativo com tema do Rick and Morty, interatividade co

Sync chat messages and various information on Telegram and Minecraft

Sync chat messages and various information on Telegram and Minecraft

Comments
  • What to import in java?

    What to import in java?

    I was trying to use this lib for a project of mine. While compiling I received this error related to the import

       [javac] C:\Users\rubyd\Desktop\extension-template\src\xyz\nisarga\DeviceInfoUtils\DeviceInfoUtils.java:23: error: package com.an does not exist
        [javac] import com.an.deviceinfo;
    

    What to import in java?

    opened by Nisarga-Developer 3
  • Is this lib an EasyDeviceInfo rip off !

    Is this lib an EasyDeviceInfo rip off !

    Not sure about this but it looks like its an EasyDeviceInfo rip off.

    if you plan to use open source code , atleast give the author due credit by forking the code.

    Thank You

    P.S. : I am the author of EasyDeviceInfo library.

    https://github.com/nisrulz/easydeviceinfo

    opened by nisrulz 1
  • getAddressLine1 returns null..

    getAddressLine1 returns null..

    String details = ""; String ipAddress = ""; try { LocationInfo locationInfo = new LocationInfo(context); DeviceLocation location = locationInfo.getLocation(); Device device = new Device(context); Network network = new Network(context); details = DEVICE_MODEL_NAME + ":" + device.getBuildBrand() + " - " + device.getModel() + "," + DEVICE_IMEI_NO + ":" + network.getIMEI() + "," + DEVICE_PHONE + ":" + network.getPhoneType() + " - " + network.getOperator() + " - " + network.getPhoneNumber() + "," + DEVICE_IP_ADD + ":" + ipAddress + "," + DEVICE_ADD + ":" + location.getAddressLine1() + "," + DEVICE_LAT + ":" + location.getLatitude() + "," + DEVICE_LOG + ":" + location.getLongitude(); Log.d(TAG, "GetDeviceInformation: " + details);

    in above code..gettting addressLine,getLatitude,getLongitude returns null..permission already given..issue due to we have to enables GPS manually.After enabled GPS it returns correct value.Please Fix it as soon as possible..

    opened by hirenpatel868 0
Owner
Anitaa Murthy
Android Developer/iOS Developer
Anitaa Murthy
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
With Viola android face detection library, you can detect faces in a bitmap, crop faces using predefined algorithm and get additional information from the detected faces.

Viola Viola android face detection library detects faces automatically from a bitmap, crop faces using the predefined algorithms, and provides supplem

Darwin Francis 58 Nov 1, 2022
A nice weather that helps you get all information including: current weather, hourly weather and also forecasts for 16 days

WeatherForecast This is an ongoing project where I fetch all the weather data using Retrofit and Kotlin Coroutines over two APIs containing both curre

null 2 Jul 26, 2022
StaticLog - super lightweight static logging for Kotlin, Java and Android

StaticLog StaticLog is a super lightweight logging library implemented in pure Kotlin (https://kotlinlang.org). It is designed to be used in Kotlin, J

Julian Pfeifer 28 Oct 3, 2022
Marvel Super Heroes | MVVM | Coroutines | DaggerHilt | LiveData

As an iOS developer, I'm learning Android and Kotlin trying to apply best practices, so I've started the same iOS project based on MARVEL, but now for ANDROID!

Míchel Marqués 2 Jun 4, 2022
It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

Shutter-Android It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android. What is Shutter? Shutter is an Androi

Levi Bostian 56 Oct 3, 2022
A React Native library making file access easier for developers as first class citizens, without the tears

React Native File Gateway A React Native library making file access easier for developers as first class citizens, without the tears. ⚠️ NOTE: This li

Jimmy Wei 4 Sep 11, 2021
An android open-source quick search/diff/download plugin.

Android Reference Intellij Plugin This library based on AndroidSourceViewer It's built with the Gradle and rewritten by kotlin, that's why it's a new

haoxiqiang 3 Nov 2, 2022
Quick route to developer options page easily

QuickRoute Using Quick Settings Tile to navigate to Developer options page without click a lot of buttons. Preview Install Can install from Google Pla

Jintin 18 Oct 1, 2021
The Klutter CLI tool gives access to all tasks to create and manage a Klutter project.

Klutter CLI The Klutter CLI tool gives access to all tasks to create and manage a Klutter project. Gettings started Download the tool. Unzip the file.

Gillian 2 Mar 31, 2022