Skip to content

Commit

Permalink
Merge pull request #2 from rvenky125/documentation
Browse files Browse the repository at this point in the history
updated document and refactored code
  • Loading branch information
rvenky125 authored May 7, 2024
2 parents 1823360 + e89769b commit 224a72b
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 360 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/publishToMC.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build and Publish to MC

on:
push:
branches:
- master
release:
types: [created]

jobs:
build:
Expand Down Expand Up @@ -46,9 +46,6 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# - name: Build
# run: ./gradlew build

- name: Publish Library on Maven Central 🚀
run: ./gradlew clean publish --no-daemon --no-parallel --no-configuration-cache --stacktrace
env:
Expand Down
234 changes: 93 additions & 141 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# kmp-device-info

![Frame 3](https://github.com/rvenky125/kmp-device-info/assets/58197145/8aaf50a4-6b7b-4226-a40d-4ce366dca6b1)

[![Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-darkgreen.svg)](https://opensource.org/licenses/Apache-2.0)
[![BuildPassing](https://shields.io/badge/build-passing-blue)](https://github.com/rvenky125/kmp-device-info/actions)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.rvenky125/kmp-device-info)](https://search.maven.org/search?q=g:%22io.github.rvenky125%22%20AND%20a:%kmp-device-info%22)

Device Information for KMP applications. Thanks to [react-native-device-info](https://github.com/react-native-device-info/react-native-device-info) for providing inspiration and resources that were utilized in this project.

getting unique id:
Expand Down Expand Up @@ -38,126 +44,108 @@ val uniqueId = DeviceInfo.getUniqueId()
</details>

<br />
Call the initialize function in Application or MainActivity and it should be called before calling other methods from device info.
Call the initialize function in Application class and it should be called before calling other methods from device info.

```kotlin
import com.famas.kmp_device_info.DeviceInfo

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
DeviceInfo.initialize(this)
....
}
```

## Proguard

If you want to use Install Referrer tracking, you will need to add this config to your Proguard config

```
-keep class com.android.installreferrer.api.** {
*;
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
DeviceInfo.initialize(this)
}
}
```

If you are experiencing issues with hasGms() on your release apks, please add the following rule to your Proguard config

```
-keep class com.google.android.gms.common.** {*;}
```

## Usage
In Common main:
In the common main of shared code:
```kotlin
import com.famas.kmp_device_info.DeviceInfo

DeviceInfo.getUniqueId()
val isEmulator = DeviceInfo.isEmulator()
```

## API

Note that many APIs are platform-specific. If there is no implementation for a platform, then you’ll get **not implemented for the platform exception**.
Note that many APIs are platform-specific. If there is no implementation for a platform, then you’ll get [NotAvailableToPlatformException](https://github.com/rvenky125/kmp-device-info/blob/182336070f48e8db4169cc3c4f8a1ce0daf97541/device-info/src/commonMain/kotlin/com/famas/kmp_device_info/Util.kt#L3).

| Method | iOS | Android | Windows (work in progress) | Web (work in progress) | visionOS (work in progress) |
| --- | --- | --- | --- | --- | --- |
| [getandroidid](#getandroidid) ||| | | |
| [getapilevel](#getapilevel) ||| | | |
| [getapplicationname](#getapplicationname) ||| | | |
| Method | iOS | Android | Windows (work in progress) | Web (work in progress) | visionOS (work in progress) |
|----------------------------------------------------------------| --- | --- | --- | --- | --- |
| [getandroidid](#getandroidid) ||| | | |
| getPlatFormType ||| | | |
| [getapilevel](#getapilevel) ||| | | |
| [getapplicationname](#getapplicationname) ||| | | |
| [getAvailableLocationProviders](#getAvailableLocationProviders) ||| | | |
| [getbaseOs](#getbaseOs) ||| | | |
| [getbuildid](#getbuildid) ||| | | |
| [getbatterylevel](#getbatterylevel) ||| | | |
| [getbootloader](#getbootloader) ||| | | |
| [getbrand](#getbrand) ||| | | |
| [getbuildnumber](#getbuildnumber) ||| | | |
| [getbundleid](#getbundleid) ||| | | |
| [iscamerapresent](#iscamerapresent) ||| | | |
| [getcarrier](#getcarrier) ||| | | |
| [getcodename](#getcodename) ||| | | |
| [getdevice](#getdevice) ||| | | |
| [getdeviceid](#getdeviceid) ||| | | |
| [getDeviceType](#getDeviceType) ||| | | |
| [getdisplay](#getdisplay) ||| | | |
| [getdevicename](#getdevicename) ||| | | |
| [getdevicetoken](#getdevicetoken) ||| | | |
| [getfirstinstalltime](#getfirstinstalltime) ||| | | |
| [getfingerprint](#getfingerprint) ||| | | |
| [getfontscale](#getfontscale) ||| | | |
| [getfreediskstorage](#getfreediskstorage) ||| | | |
| [getfreediskstorageold](#getfreediskstorageold) ||| | | |
| [gethardware](#gethardware) ||| | | |
| [gethost](#gethost) ||| | | |
| [getHostNames](#getHostNames) ||| | | |
| [getipaddress](#getipaddress) ||| | | |
| [getincremental](#getincremental) ||| | | |
| [getinstallerpackagename](#getinstallerpackagename) ||| | | |
| [getinstallreferrer](#getinstallreferrer) ||| | | |
| [getlastupdatetime](#getlastupdatetime) ||| | | |
| [getmacaddress](#getmacaddress) ||| | | |
| [getmanufacturer](#getmanufacturer) ||| | | |
| [getmaxmemory](#getmaxmemory) ||| | | |
| [getmodel](#getmodel) ||| | | |
| [getphonenumber](#getphonenumber) ||| | | |
| [getpowerstate](#getpowerstate) ||| | | |
| [getproduct](#getproduct) ||| | | |
| [getPreviewSdkInt](#getPreviewSdkInt) ||| | | |
| [getreadableversion](#getreadableversion) ||| | | |
| [getserialnumber](#getserialnumber) ||| | | |
| [getsecuritypatch](#getsecuritypatch) ||| | | |
| [getSystemAvailableFeatures](#getSystemAvailableFeatures) ||| | | |
| [getsystemname](#getsystemname) ||| | | |
| [getsystemversion](#getsystemversion) ||| | | |
| [gettags](#gettags) ||| | | |
| [gettype](#gettype) ||| | | |
| [gettotaldiskcapacity](#gettotaldiskcapacity) ||| | | |
| [gettotaldiskcapacityold](#gettotaldiskcapacityold) ||| | | |
| [gettotalmemory](#gettotalmemory) ||| | | |
| [getuniqueid](#getuniqueid) ||| | | |
| [getusedmemory](#getusedmemory) ||| | | |
| [getuseragent](#getuseragent) ||| | | |
| [getversion](#getversion) ||| | | |
| [getBrightness](#getBrightness) ||| | | |
| [hasGms](#hasGms) ||| | | |
| [hasHms](#hasHms) ||| | | |
| [hasNotch](#hasNotch) ||| | | |
| [hasDynamicIsland](#hasDynamicIsland) ||| | | |
| [hassystemfeaturefeature](#hassystemfeaturefeature) ||| | | |
| [isairplanemode](#isairplanemode) ||| | | |
| [isbatterycharging](#isbatterycharging) ||| | | |
| [isemulator](#isemulator) ||| | | |
| [iskeyboardconnected](#iskeyboardconnected) ||| | | |
| [isLandscape](#isLandscape) ||| | | |
| [isLocationEnabled](#isLocationEnabled) ||| | | |
| [ismouseconneted](#ismouseconneted) ||| | | |
| [isHeadphonesConnected](#isHeadphonesConnected) ||| | | |
| [ispinorfingerprintset](#ispinorfingerprintset) ||| | | |
| [istablet](#istablet) ||| | | |
| [istabletmode](#istabletmode) ||| | | |
| [supported32BitAbis](#supported32BitAbis) ||| | | |
| [supported64BitAbis](#supported64BitAbis) ||| | | |
| [supportedAbis](#supportedAbis) ||| | | |
| [syncuniqueid](#syncuniqueid) ||| | | |
| [getSupportedMediaTypeList](#getSupportedMediaTypeList) ||| | | |
| [getbaseOs](#getbaseOs) ||| | | |
| [getbuildid](#getbuildid) ||| | | |
| [getbatterylevel](#getbatterylevel) ||| | | |
| [getbootloader](#getbootloader) ||| | | |
| [getbrand](#getbrand) ||| | | |
| [getbuildnumber](#getbuildnumber) ||| | | |
| [getbundleid](#getbundleid) ||| | | |
| [iscamerapresent](#iscamerapresent) ||| | | |
| [getcarrier](#getcarrier) ||| | | |
| [getcodename](#getcodename) ||| | | |
| [getdevice](#getdevice) ||| | | |
| [getdeviceid](#getdeviceid) ||| | | |
| [getDeviceType](#getDeviceType) ||| | | |
| [getdisplay](#getdisplay) ||| | | |
| [getdevicename](#getdevicename) ||| | | |
| [getdevicetoken](#getdevicetoken) ||| | | |
| [getfirstinstalltime](#getfirstinstalltime) ||| | | |
| [getfingerprint](#getfingerprint) ||| | | |
| [getfontscale](#getfontscale) ||| | | |
| [getfreediskstorage](#getfreediskstorage) ||| | | |
| [getfreediskstorageold](#getfreediskstorageold) ||| | | |
| [gethardware](#gethardware) ||| | | |
| [gethost](#gethost) ||| | | |
| [getHostNames](#getHostNames) ||| | | |
| [getipaddress](#getipaddress) ||| | | |
| [getincremental](#getincremental) ||| | | |
| [getinstallerpackagename](#getinstallerpackagename) ||| | | |
| [getlastupdatetime](#getlastupdatetime) ||| | | |
| [getmacaddress](#getmacaddress) ||| | | |
| [getmanufacturer](#getmanufacturer) ||| | | |
| [getmaxmemory](#getmaxmemory) ||| | | |
| [getmodel](#getmodel) ||| | | |
| [getphonenumber](#getphonenumber) ||| | | |
| [getpowerstate](#getpowerstate) ||| | | |
| [getproduct](#getproduct) ||| | | |
| [getPreviewSdkInt](#getPreviewSdkInt) ||| | | |
| [getreadableversion](#getreadableversion) ||| | | |
| [getserialnumber](#getserialnumber) ||| | | |
| [getsecuritypatch](#getsecuritypatch) ||| | | |
| [getSystemAvailableFeatures](#getSystemAvailableFeatures) ||| | | |
| [getsystemname](#getsystemname) ||| | | |
| [getsystemversion](#getsystemversion) ||| | | |
| [gettags](#gettags) ||| | | |
| [gettype](#gettype) ||| | | |
| [gettotaldiskcapacity](#gettotaldiskcapacity) ||| | | |
| [gettotaldiskcapacityold](#gettotaldiskcapacityold) ||| | | |
| [gettotalmemory](#gettotalmemory) ||| | | |
| [getuniqueid](#getuniqueid) ||| | | |
| [getusedmemory](#getusedmemory) ||| | | |
| [getuseragent](#getuseragent) ||| | | |
| [getversion](#getversion) ||| | | |
| [getBrightness](#getBrightness) ||| | | |
| [hasNotch](#hasNotch) ||| | | |
| [hasDynamicIsland](#hasDynamicIsland) ||| | | |
| [hassystemfeaturefeature](#hassystemfeaturefeature) ||| | | |
| [isairplanemode](#isairplanemode) ||| | | |
| [isbatterycharging](#isbatterycharging) ||| | | |
| [isemulator](#isemulator) ||| | | |
| [iskeyboardconnected](#iskeyboardconnected) ||| | | |
| [isLandscape](#isLandscape) ||| | | |
| [isLocationEnabled](#isLocationEnabled) ||| | | |
| [ismouseconneted](#ismouseconneted) ||| | | |
| [isHeadphonesConnected](#isHeadphonesConnected) ||| | | |
| [ispinorfingerprintset](#ispinorfingerprintset) ||| | | |
| [istablet](#istablet) ||| | | |
| [istabletmode](#istabletmode) ||| | | |
| [supported32BitAbis](#supported32BitAbis) ||| | | |
| [supported64BitAbis](#supported64BitAbis) ||| | | |
| [supportedAbis](#supportedAbis) ||| | | |
| [getSupportedMediaTypeList](#getSupportedMediaTypeList) ||| | | |

### getApiLevel()

Expand Down Expand Up @@ -328,7 +316,6 @@ Old implementation of method that gets available storage size, in bytes.
> that is shared across all applications (does not enforce permissions). Traditionally this is
> an SD card, but it may also be implemented as built-in storage in a device that is distinct
> from the protected internal storage and can be mounted as a filesystem on a computer.
>
---

Expand Down Expand Up @@ -371,12 +358,6 @@ The internal value used by the underlying source control to represent this build

---

### getInstallReferrer()

Gets the referrer string upon application installation.

---

### getLastUpdateTime()

Gets the time at which the app was last updated, in milliseconds.
Expand Down Expand Up @@ -542,16 +523,6 @@ Beware: The IDFV is calculated using your bundle identifier and thus will be dif
>
---

### syncUniqueId()

This method is intended for iOS.

This synchronizes uniqueId with `[IDFV](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor)` or sets new a random string.

On iOS it uses the `DeviceUID` uid identifier.
On other platforms it just call `getUniqueId()` in this module.

### Notes

> If user moved or restored data from one iOS device to second iOS device then he will have two different devices with same uniqueId in Keychain/NSUserDefaults. User can call syncUniqueId() on new iOS device. That will update his uniqueId from IDFV or a random string.
Expand Down Expand Up @@ -657,18 +628,6 @@ Tells if the device has a mouse connected.

---

### hasGms()

Tells if the device supports Google Mobile Services.

---

### hasHms()

Tells if the device supports Huawei Mobile Services.

---

### hasNotch()

Tells if the device has a notch.
Expand All @@ -683,15 +642,8 @@ Tells if the device has a dynamic island.

### getDeviceType()

Returns the device’s type as a string, which will be one of:
Returns the device’s type class, which will be one of:

- `Handset`
- `Tablet`
- `Tv`
- `Desktop`
- `GamingConsole`
- `Headset`
- `unknown`

---

Expand Down Expand Up @@ -770,4 +722,4 @@ Gets the current brightness level of the device’s main screen. Currently iOS o


## Contributing
There aren't any particular guidelines for sharing your expertise and strengthening the open-source community. Just remember to raise an issue or initiate a discussion beforehand, so there are no surprises when you submit a pull request.
There aren't any particular guidelines for sharing your expertise and strengthening the open-source community. Just remember to raise an issue or initiate a discussion beforehand, so there are no surprises when you submit a pull request.
2 changes: 1 addition & 1 deletion device-info/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.GradleKpmIosX64Variant

val libVersion = "0.0.15-alpha"
val libVersion = "0.0.16-alpha"
val artifactId = "kmp-device-info"
val groupId = "io.github.rvenky125"

Expand Down
Loading

0 comments on commit 224a72b

Please sign in to comment.