• Stars
    star
    204
  • Rank 192,008 (Top 4 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

Android-Cheat-sheet

Cheat Sheet for Android Interviews
Java
2,162
star
2

Biometric-Auth-Sample

Add Biometric Authentication to any Android app
Java
246
star
3

TrailersApp

A simple demo project for The Movie DB based on MVVM clean architecture.
Java
197
star
4

PagingLibrary-Sample

An open source app that is refactored to demo Paging Library from Android Jetpack
Java
170
star
5

Today-I-Learned

A collection of small things I learn day to day across a variety of languages and technologies
155
star
6

RoomDb-Sample

A simple notes app to demo Room + LiveData implementation in Android
Java
122
star
7

Wifi-Connect

A library project to connect two devices using Wifi-Direct
Java
105
star
8

ConstraintLayout-Sample

A demo app to showcase constraint layout implementation in Android
Java
105
star
9

OnboardingSample

Beginners - A demo of an onboarding screen in iOS using Swift
Swift
97
star
10

Dagger2-Sample

A sample app to demo how to implement dagger in Android using Dagger Android Support library
Java
77
star
11

Github-Trending-Repos

An Android App that lists the most trending repositories from Github.
Java
60
star
12

RxAndroid-Sample

A list of concise write ups on the implementation of RxJava in Android
Java
36
star
13

Optimize

Android library for displaying data based on JSON configuration fetched from server. With this library, you can kiss goodbye to string.xml, dimen.xml, arrays.xml. Keep all your string/integer/array config in one file. The library will automatically fetch the data from the url you provide.
Java
35
star
14

CustomFontView

Custom View classes for TextView, EditText & Buttons - to set custom fonts
Java
27
star
15

Inshorts

A demo app news app for a hackathon - includes MVP architecture example
Java
23
star
16

RxNetworkEvent-Example

This is a sample app to demonstrate error handling using Retrofit2 and RxJava2
Java
22
star
17

AESEncryption

A demo of how to implement AES encryption in Android & iOS
Swift
21
star
18

Trailers

An open source app that is refactored to demo MVVM architecture
Java
20
star
19

otpview

A simple custom view class to enter otp
Java
19
star
20

GameOfThronesTrivia

An open source app that is refactored to demo ViewModel and LiveData
Java
17
star
21

DataBindingExample

A demo of how to implement Data Binding in Android app
Java
11
star
22

Jni-Sample

A simple project that demonstrates the use of jni to communicate between native and Java code in Android
Java
10
star
23

Ussd-app

A POC app for USSD implementation in Android
Java
6
star
24

RequestTask

Android library wrapper for HttpUrlConnection
Java
5
star
25

Github-Repo-Sample

A demo app that follows clean architecture which includes:
Kotlin
3
star
26

VDOPlayer

A simple video player app
Java
2
star