kandi background
Explore Kits

react-native-device-info | Device Information for React Native iOS and Android | iOS library

 by   react-native-community Java Version: v6.0.2 License: MIT

 by   react-native-community Java Version: v6.0.2 License: MIT

Download this library from

kandi X-RAY | react-native-device-info Summary

react-native-device-info is a Java library typically used in Mobile, iOS, React Native applications. react-native-device-info has no bugs, it has no vulnerabilities, it has a Permissive License and it has high support. However react-native-device-info build file is not available. You can install using 'npm i @scxkkj/react-native-device-info' or download it from GitHub, npm.
<!-- markdownlint-disable MD024 MD034 MD033 -→.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • react-native-device-info has a highly active ecosystem.
  • It has 4932 star(s) with 1163 fork(s). There are 74 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 28 open issues and 615 have been closed. On average issues are closed in 44 days. There are 6 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of react-native-device-info is v6.0.2
This Library - Support
Best in #iOS
Average in #iOS
This Library - Support
Best in #iOS
Average in #iOS

quality kandi Quality

  • react-native-device-info has 0 bugs and 0 code smells.
This Library - Quality
Best in #iOS
Average in #iOS
This Library - Quality
Best in #iOS
Average in #iOS

securitySecurity

  • react-native-device-info has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • react-native-device-info code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
This Library - Security
Best in #iOS
Average in #iOS
This Library - Security
Best in #iOS
Average in #iOS

license License

  • react-native-device-info is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
This Library - License
Best in #iOS
Average in #iOS
This Library - License
Best in #iOS
Average in #iOS

buildReuse

  • react-native-device-info releases are available to install and integrate.
  • Deployable package is available in npm.
  • react-native-device-info has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions, examples and code snippets are available.
  • It has 1219 lines of code, 145 functions and 35 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
This Library - Reuse
Best in #iOS
Average in #iOS
This Library - Reuse
Best in #iOS
Average in #iOS
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

react-native-device-info Key Features

Device Information for React Native iOS and Android

Installation

copy iconCopydownload iconDownload
npm install --save react-native-device-info

AndroidX Support

copy iconCopydownload iconDownload
...
  ext {
    // dependency versions

    We have 3 options for deviceId:
    //Option 1 (latest):
    firebaseIidVersion = "19.0.1" // default: "19.0.1"
    //Option 2 (legacy GooglePlay dependency but using AndroidX):
    googlePlayServicesIidVersion = "17.0.0" // default: "17.0.0" - AndroidX
    //Option 3 (legacy GooglePlay dependency before AndroidX):
    googlePlayServicesIidVersion = "16.0.1"


    //include as needed:
    compileSdkVersion = "28" // default: 28 (28 is required for AndroidX)
    targetSdkVersion = "28" // default: 28 (28 is required for AndroidX)
    supportLibVersion = '1.0.2' // Use '28.0.0' or don't specify for old libraries, '1.0.2' or similar for AndroidX
    mediaCompatVersion = '1.0.1' // Do not specify if using old libraries, specify '1.0.1' or similar for androidx.media:media dependency
    supportV4Version = '1.0.0' // Do not specify if using old libraries, specify '1.0.0' or similar for androidx.legacy:legacy-support-v4 dependency
  }
...

Automatic

copy iconCopydownload iconDownload
react-native link react-native-device-info

Manual

copy iconCopydownload iconDownload
mv ios/Podfile .
react-native link react-native-device-info
mv Podfile ios

Usage

copy iconCopydownload iconDownload
import DeviceInfo from 'react-native-device-info';

// or ES6+ destructured imports

import { getUniqueId, getManufacturer } from 'react-native-device-info';

getApiLevel()

copy iconCopydownload iconDownload
DeviceInfo.getApiLevel().then(apiLevel =&gt; {
  // iOS: ?
  // Android: 25
  // Windows: ?
});

getAndroidId()

copy iconCopydownload iconDownload
DeviceInfo.getAndroidId().then(androidId =&gt; {
  // androidId here
});

getApplicationName()

copy iconCopydownload iconDownload
let appName = DeviceInfo.getApplicationName();
// AwesomeApp

getBaseOs()

copy iconCopydownload iconDownload
DeviceInfo.getBaseOs().then(baseOs =&gt; {
  // "Windows", "Android" etc
});

getBatteryLevel()

copy iconCopydownload iconDownload
DeviceInfo.getBatteryLevel().then(batteryLevel =&gt; {
  // 0.759999
});

getBootloader()

copy iconCopydownload iconDownload
DeviceInfo.getBootloader().then(bootloader =&gt; {
  // "mw8998-002.0069.00"
});

getBrand()

copy iconCopydownload iconDownload
let brand = DeviceInfo.getBrand();
// iOS: "Apple"
// Android: "xiaomi"
// Windows: ?

getBuildNumber()

copy iconCopydownload iconDownload
let buildNumber = DeviceInfo.getBuildNumber();
// iOS: "89"
// Android: "4"
// Windows: ?

getBundleId()

copy iconCopydownload iconDownload
let bundleId = DeviceInfo.getBundleId();
// "com.example.AwesomeApp"

isCameraPresent()

copy iconCopydownload iconDownload
DeviceInfo.isCameraPresent()
  .then(isCameraPresent =&gt; {
    // true or false
  })
  .catch(cameraAccessException =&gt; {
    // is thrown if a camera device could not be queried or opened by the CameraManager on Android
  });

getCarrier()

copy iconCopydownload iconDownload
DeviceInfo.getCarrier().then(carrier =&gt; {
  // "SOFTBANK"
});

getCodename()

copy iconCopydownload iconDownload
DeviceInfo.getCodename().then(codename =&gt; {
  // "REL"
});

getDevice()

copy iconCopydownload iconDownload
DeviceInfo.getDevice().then(device =&gt; {
  // "walleye"
});

getDeviceId()

copy iconCopydownload iconDownload
let deviceId = DeviceInfo.getDeviceId();
// iOS: "iPhone7,2"
// Android: "goldfish"
// Windows: ?

getDisplay()

copy iconCopydownload iconDownload
DeviceInfo.getDisplay().then(display =&gt; {
  // "OPM2.171026.006.G1"
});

getDeviceName()

copy iconCopydownload iconDownload
DeviceInfo.getDeviceName().then(deviceName =&gt; {
  // iOS: "Becca's iPhone 6"
  // Android: ?
  // Windows: ?
});

getDeviceToken()

copy iconCopydownload iconDownload
DeviceInfo.getDeviceToken().then(deviceToken =&gt; {
  // iOS: "a2Jqsd0kanz..."
});

getFirstInstallTime()

copy iconCopydownload iconDownload
DeviceInfo.getFirstInstallTime().then(firstInstallTime =&gt; {
  // Android: 1517681764528
});

getFingerprint()

copy iconCopydownload iconDownload
DeviceInfo.getFingerprint().then(fingerprint =&gt; {
  // "google/walleye/walleye:8.1.0/OPM2.171026.006.G1/4820017:user/release-keys"
});

getFontScale()

copy iconCopydownload iconDownload
DeviceInfo.getFontScale().then(fontScale =&gt; {
  // 1.2
});

getFreeDiskStorage()

copy iconCopydownload iconDownload
DeviceInfo.getFreeDiskStorage().then(freeDiskStorage =&gt; {
  // Android: 17179869184
  // iOS: 17179869184
});

getFreeDiskStorageNew()

copy iconCopydownload iconDownload
DeviceInfo.getFreeDiskStorage().then(freeDiskStorage =&gt; {
  // Android: 17179869184
  // iOS: 17179869184
});

getHardware()

copy iconCopydownload iconDownload
DeviceInfo.getHardware().then(hardware =&gt; {
  // "walleye"
};

getHost()

copy iconCopydownload iconDownload
DeviceInfo.getHost().then(host =&gt; {
  // "wprd10.hot.corp.google.com"
});

getIpAddress()

copy iconCopydownload iconDownload
DeviceInfo.getIpAddress().then(ip =&gt; {
  // "92.168.32.44"
});

getIncremental()

copy iconCopydownload iconDownload
DeviceInfo.getIncremental().then(incremental =&gt; {
  // "4820017"
});

getInstallerPackageName()

copy iconCopydownload iconDownload
DeviceInfo.getInstallerPackageName().then(installerPackageName =&gt; {
  // Play Store: "com.android.vending"
  // Amazon: "com.amazon.venezia"
  // Samsung App Store: "com.sec.android.app.samsungapps"
  // Developer, iOS: "unknown"
});

getInstallReferrer()

copy iconCopydownload iconDownload
DeviceInfo.getInstallReferrer().then(installReferrer =&gt; {
  // If the app was installed from https://play.google.com/store/apps/details?id=com.myapp&amp;referrer=my_install_referrer
  // the result will be "my_install_referrer"
});

getInstanceId()

copy iconCopydownload iconDownload
DeviceInfo.getInstanceId().then(instanceId =&gt; {
  // Android: ?
});

getLastUpdateTime()

copy iconCopydownload iconDownload
DeviceInfo.getLastUpdateTime().then(lastUpdateTime =&gt; {
  // Android: 1517681764992
});

getMacAddress()

copy iconCopydownload iconDownload
DeviceInfo.getMacAddress().then(mac =&gt; {
  // "E5:12:D8:E5:69:97"
});

getManufacturer()

copy iconCopydownload iconDownload
DeviceInfo.getManufacturer().then(manufacturer =&gt; {
  // iOS: "Apple"
  // Android: "Google"
  // Windows: ?
});

getMaxMemory()

copy iconCopydownload iconDownload
DeviceInfo.getMaxMemory().then(maxMemory =&gt; {
  // 402653183
});

getModel()

copy iconCopydownload iconDownload
let model = DeviceInfo.getModel();
// iOS: ?
// Android: ?
// Windows: ?

getPhoneNumber()

copy iconCopydownload iconDownload
DeviceInfo.getPhoneNumber().then(phoneNumber =&gt; {
  // Android: null return: no permission, empty string: unprogrammed or empty SIM1, e.g. "+15555215558": normal return value
});

getPowerState()

copy iconCopydownload iconDownload
DeviceInfo.getPowerState().then(state =&gt; {
  // {
  //   batteryLevel: 0.759999,
  //   batteryState: 'unplugged',
  //   lowPowerMode: false,
  // }
});

getProduct()

copy iconCopydownload iconDownload
DeviceInfo.getProduct().then(product =&gt; {
  // "walleye"
});

getPreviewSdkInt()

copy iconCopydownload iconDownload
DeviceInfo.getPreviewSdkInt().then(previewSdkInt =&gt; {
  // 0
});

getReadableVersion()

copy iconCopydownload iconDownload
let readableVersion = DeviceInfo.getReadableVersion();
// iOS: 1.0.1.32
// Android: 1.0.1.234
// Windows: ?

getSerialNumber()

copy iconCopydownload iconDownload
DeviceInfo.getSerialNumber().then(serialNumber =&gt; {
  // iOS: unknown
  // Android: ? (maybe a serial number, if your app is privileged)
  // Windows: unknown
});

getSecurityPatch()

copy iconCopydownload iconDownload
DeviceInfo.getSecurityPatch().then(securityPatch =&gt; {
  // "2018-07-05"
});

getSystemName()

copy iconCopydownload iconDownload
let systemName = DeviceInfo.getSystemName();
// iOS: "iOS" on newer iOS devices "iPhone OS" on older devices, including older iPad's.
// Android: "Android"
// Windows: ?

getSystemVersion()

copy iconCopydownload iconDownload
let systemVersion = DeviceInfo.getSystemVersion();
// iOS: "11.0"
// Android: "7.1.1"
// Windows: ?

getBuildId()

copy iconCopydownload iconDownload
DeviceInfo.getBuildId().then(buildId =&gt; {
  // iOS: "12A269"
  // tvOS: not available
  // Android: "13D15"
  // Windows: not available
});

getTags()

copy iconCopydownload iconDownload
DeviceInfo.getTags().then(tags =&gt; {
  // "release-keys, unsigned, debug",
});

getType()

copy iconCopydownload iconDownload
DeviceInfo.getType().then(type =&gt; {
  // "user", "eng"
});

getTotalDiskCapacity()

copy iconCopydownload iconDownload
DeviceInfo.getTotalDiskCapacity().then(capacity =&gt; {
  // Android: 17179869184
  // iOS: 17179869184
});

getTotalDiskCapacityNew()

copy iconCopydownload iconDownload
DeviceInfo.getTotalDiskCapacity().then(capacity =&gt; {
  // Android: 17179869184
  // iOS: 17179869184
});

getTotalMemory()

copy iconCopydownload iconDownload
DeviceInfo.getTotalMemory().then(totalMemory =&gt; {
  // 1995018240
});

getUniqueId()

copy iconCopydownload iconDownload
let uniqueId = DeviceInfo.getUniqueId();
// iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
// Android: "dd96dec43fb81c97"
// Windows: ?

syncUniqueId()

copy iconCopydownload iconDownload
DeviceInfo.syncUniqueId().then(uniqueId =&gt; {
  // iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
  // Android: "dd96dec43fb81c97"
  // Windows: ?
});

getUsedMemory()

copy iconCopydownload iconDownload
DeviceInfo.getUsedMemory().then(usedMemory =&gt; {
  // 23452345
});

getUserAgent()

copy iconCopydownload iconDownload
DeviceInfo.getUserAgent().then(userAgent =&gt; {
  // iOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143"
  // tvOS: not available
  // Android: ?
  // Windows: ?
});

getVersion()

copy iconCopydownload iconDownload
let version = DeviceInfo.getVersion();
// iOS: "1.0"
// Android: "1.0"
// Windows: ?

isAirplaneMode()

copy iconCopydownload iconDownload
DeviceInfo.isAirplaneMode().then(airplaneModeOn =&gt; {
  // false
});

isBatteryCharging()

copy iconCopydownload iconDownload
DeviceInfo.isBatteryCharging().then(isCharging =&gt; {
  // true or false
});

isEmulator()

copy iconCopydownload iconDownload
DeviceInfo.isEmulator().then(isEmulator =&gt; {
  // false
});

isPinOrFingerprintSet()

copy iconCopydownload iconDownload
DeviceInfo.isPinOrFingerprintSet().then(isPinOrFingerprintSet =&gt; {
  if (!isPinOrFingerprintSet) {
    // ...
  }
});

isTablet()

copy iconCopydownload iconDownload
let isTablet = DeviceInfo.isTablet();
// true

isLandscape()

copy iconCopydownload iconDownload
DeviceInfo.isLandscape().then(isLandscape =&gt; {
  // true
});

hasNotch()

copy iconCopydownload iconDownload
let hasNotch = DeviceInfo.hasNotch();
  // true

getDeviceType()

copy iconCopydownload iconDownload
let type = DeviceInfo.getDeviceType();
// 'Handset'

supported32BitAbis()

copy iconCopydownload iconDownload
DeviceInfo.supported32BitAbis().then(abis =&gt; {
  // ["armeabi-v7a", "armeabi"]
});

supported64BitAbis()

copy iconCopydownload iconDownload
DeviceInfo.supported64BitAbis().then(abis =&gt; {
  // ["arm64-v8a"]
});

supportedAbis()

copy iconCopydownload iconDownload
DeviceInfo.supportedAbis().then(abis =&gt; {
  // [ "arm64 v8", "Intel x86-64h Haswell", "arm64-v8a", "armeabi-v7a", "armeabi" ]
});

hasSystemFeature(feature)

copy iconCopydownload iconDownload
DeviceInfo.hasSystemFeature('amazon.hardware.fire_tv').then(hasFeature =&gt; {
  // true or false
});

getSystemAvailableFeatures()

copy iconCopydownload iconDownload
DeviceInfo.getSystemAvailableFeatures().then(features =&gt; {
  // ["android.software.backup", "android.hardware.screen.landscape", "android.hardware.wifi", ...]
});

isLocationEnabled()

copy iconCopydownload iconDownload
DeviceInfo.isLocationEnabled().then(enabled =&gt; {
  // true or false
});

isHeadphonesConnected()

copy iconCopydownload iconDownload
DeviceInfo.isHeadphonesConnected().then(enabled =&gt; {
  // true or false
})

getAvailableLocationProviders()

copy iconCopydownload iconDownload
DeviceInfo.getAvailableLocationProviders().then(providers =&gt; {
  // {
  //   gps: true
  //   network: true
  //   passive: true
  // }
});

useBatteryLevel or RNDeviceInfo_batteryLevelDidChange

copy iconCopydownload iconDownload
import { useBatteryLevel } from 'react-native-device-info'

const batteryLevel = useBatteryLevel(); // 0.759999

&lt;Text&gt;{ batteryLevel }&lt;/Text&gt;

useBatteryLevelIsLow or RNDeviceInfo_batteryLevelIsLow

copy iconCopydownload iconDownload
import { useBatteryLevelIsLow } from 'react-native-device-info'

const batteryLevelIsLow = useBatteryLevelIsLow(); // 0.19

&lt;Text&gt;{ batteryLevelIsLow }&lt;/Text&gt;

usePowerState or RNDeviceInfo_powerStateDidChange

copy iconCopydownload iconDownload
import { usePowerState } from 'react-native-device-info'

const powerState = usePowerState(); // 'charging'

&lt;Text&gt;{ powerState }&lt;/Text&gt;

useFirstInstallTime

copy iconCopydownload iconDownload
import { usePowerState } from 'react-native-device-info';

const { loading, result } = useFirstInstallTime(); // { loading: true, result: 1517681764528}

&lt;Text&gt;{loading ? 'loading...' : result}&lt;/Text&gt;;

useDeviceName

copy iconCopydownload iconDownload
import { useDeviceName } from 'react-native-device-info';

const { loading, result } = useDeviceName(); // { loading: true, result: "Becca's iPhone 6"}

&lt;Text&gt;{loading ? 'loading...' : result}&lt;/Text&gt;;

useHasSystemFeature

copy iconCopydownload iconDownload
import { useHasSystemFeature } from 'react-native-device-info';

const { loading, result } = useHasSystemFeature('amazon.hardware.fire_tv'); // { loading: true, result: false }

&lt;Text&gt;{loading ? 'loading...' : result}&lt;/Text&gt;;

useIsEmulator

copy iconCopydownload iconDownload
import { useIsEmulator } from 'react-native-device-info';

const { loading, result } = useIsEmulator(); // { loading: true, result: false }

&lt;Text&gt;{loading ? 'loading...' : result}&lt;/Text&gt;;

Trying to declare variable within useEffect:

copy iconCopydownload iconDownload
setDevice(contents);

React Native WatermelonDB Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

copy iconCopydownload iconDownload
...
myScheme,
...
scheme: myScheme,
...
myScheme,
...
scheme: myScheme,

this permision (android.permission.QUERY_ALL_PACKAGES) was automatically added to Manifest

copy iconCopydownload iconDownload
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
        tools:node="remove" tools:ignore="QueryAllPackagesPermission" />

I want to restart a circular progress bar after 30 seconds

copy iconCopydownload iconDownload
const useProgress = (maxTimeInSeconds = 30) => {
    const [elapsedTime, setElapsedTime] = useState(0);
        useEffect(() => {
            const intervalId = setInterval(() => {
                setElapsedTime((t) => t + 1);
            }, 1000);
        return () => clearInterval(intervalId);
    }, []);
    return (elapsedTime % maxTimeInSeconds) / maxTimeInSeconds;
};

const progress = useProgress();
const useProgress = (maxTimeInSeconds = 30) => {
    const [initialTime] = useState(() => +new Date());
    const [counter, setCounter] = useState(0);
    useEffect(() => {
        const intervalId = setInterval(() => {
            setCounter((t) => t + 1);
        }, 1000);
        return () => clearInterval(intervalId);
    }, []);

    const elapsedTime = Math.floor(((+new Date()) - initialTime) / 1000);
    if (elapsedTime == 30) {
        return maxTimeInSeconds;
    }
    
    return (elapsedTime % maxTimeInSeconds) / maxTimeInSeconds;
};
const useProgress = (maxTimeInSeconds = 30) => {
    const [elapsedTime, setElapsedTime] = useState(0);
        useEffect(() => {
            const intervalId = setInterval(() => {
                setElapsedTime((t) => t + 1);
            }, 1000);
        return () => clearInterval(intervalId);
    }, []);
    return (elapsedTime % maxTimeInSeconds) / maxTimeInSeconds;
};

const progress = useProgress();
const useProgress = (maxTimeInSeconds = 30) => {
    const [initialTime] = useState(() => +new Date());
    const [counter, setCounter] = useState(0);
    useEffect(() => {
        const intervalId = setInterval(() => {
            setCounter((t) => t + 1);
        }, 1000);
        return () => clearInterval(intervalId);
    }, []);

    const elapsedTime = Math.floor(((+new Date()) - initialTime) / 1000);
    if (elapsedTime == 30) {
        return maxTimeInSeconds;
    }
    
    return (elapsedTime % maxTimeInSeconds) / maxTimeInSeconds;
};

React Native code broke after react-native-device-info

copy iconCopydownload iconDownload
yarn add react-native-msal@3.1.1

Getting Cannot find module 'react-apollo/test-utils' error in jest teact native

copy iconCopydownload iconDownload
import { MockedProvider } from '@apollo/client/testing';

Writing texts in the body of the sent email one under the other -React Native

copy iconCopydownload iconDownload
const [comment, setComment] = useState('');

const brand = DeviceInfo.getBrand();                 // Sony
const model = DeviceInfo.getModel();                 // G8341
const systemName = DeviceInfo.getSystemName();       // Android
const systemVersion = DeviceInfo.getSystemVersion(); // 9

const emailAddresses = [
  'example@gmail.com',
  'example2@gmail.com',
];

const to = emailAddresses.join(',');
const subject = 'Error';
const body = `${brand} ${model}\n${systemName} ${systemVersion}\n${comment}`;

const url = `mailto:${to}?subject=${subject}&body=${body}`;

// …
Sony G8341
Android 9
Comments here
const [comment, setComment] = useState('');

const brand = DeviceInfo.getBrand();                 // Sony
const model = DeviceInfo.getModel();                 // G8341
const systemName = DeviceInfo.getSystemName();       // Android
const systemVersion = DeviceInfo.getSystemVersion(); // 9

const emailAddresses = [
  'example@gmail.com',
  'example2@gmail.com',
];

const to = emailAddresses.join(',');
const subject = 'Error';
const body = `${brand} ${model}\n${systemName} ${systemVersion}\n${comment}`;

const url = `mailto:${to}?subject=${subject}&body=${body}`;

// …
Sony G8341
Android 9
Comments here

React Native Android Duplicate class com.google.android.gms.gcm.PendingCallback found in modules jetified-firebase-jobdispatcher-0.6.0-runtime.jar

copy iconCopydownload iconDownload
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.0.1')

// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-analytics'

implementation "com.google.android.gms:play-services-gcm:17.0.0"
...
configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-gcm:16.1.0'
            force 'com.google.android.gms:play-services-base:16.1.0'
            force 'com.google.firebase:firebase-core:16.0.6'
            force 'com.google.firebase:firebase-messaging:17.6.0'
        }
    }
implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-messaging:15.0.2"
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.0.1')

// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-analytics'

implementation "com.google.android.gms:play-services-gcm:17.0.0"
...
configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-gcm:16.1.0'
            force 'com.google.android.gms:play-services-base:16.1.0'
            force 'com.google.firebase:firebase-core:16.0.6'
            force 'com.google.firebase:firebase-messaging:17.6.0'
        }
    }
implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-messaging:15.0.2"

Task :app:checkDebugDuplicateClasses FAILED java.lang.RuntimeException: Duplicate class com.google.android.gms.internal.firebase_messaging.zza found

copy iconCopydownload iconDownload
firebaseVersion = "21.1.0"
  firebaseMessagingVersion = "21.1.0"
   buildToolsVersion = "29.0.2"
   firebaseCoreVersion = "17.0.0"
   firebaseVersion = "21.1.0"
implementation 'com.google.firebase:firebase-messaging:21.1.0'
firebaseVersion = "21.1.0"
  firebaseMessagingVersion = "21.1.0"
   buildToolsVersion = "29.0.2"
   firebaseCoreVersion = "17.0.0"
   firebaseVersion = "21.1.0"
implementation 'com.google.firebase:firebase-messaging:21.1.0'
firebaseVersion = "21.1.0"
  firebaseMessagingVersion = "21.1.0"
   buildToolsVersion = "29.0.2"
   firebaseCoreVersion = "17.0.0"
   firebaseVersion = "21.1.0"
implementation 'com.google.firebase:firebase-messaging:21.1.0'

How to manage FCM push tokens

copy iconCopydownload iconDownload
  const response = await admin.messaging().sendToDevice(tokens, payload);
  // For each message check if there was an error.
  const tokensToRemove = [];
  response.results.forEach((result, index) => {
    const error = result.error;
    if (error) {
      functions.logger.error(
        'Failure sending notification to',
        tokens[index],
        error
      );
      // Cleanup the tokens who are not registered anymore.
      if (error.code === 'messaging/invalid-registration-token' ||
          error.code === 'messaging/registration-token-not-registered') {
        tokensToRemove.push(tokensSnapshot.ref.child(tokens[index]).remove());
      }
    }
  });
  return Promise.all(tokensToRemove);

Community Discussions

Trending Discussions on react-native-device-info
  • Trying to declare variable within useEffect:
  • Get SIM number on android phone with React Native
  • Could not find com.google.android:flexbox:1.0.0 react-native-intercom
  • react-native &quot;Export statement may only appear at top level&quot; was working fine until cleaning project how do I find out the issue?
  • React Native WatermelonDB Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
  • this permision (android.permission.QUERY_ALL_PACKAGES) was automatically added to Manifest
  • I want to restart a circular progress bar after 30 seconds
  • React Native code broke after react-native-device-info
  • Getting Cannot find module 'react-apollo/test-utils' error in jest teact native
  • Writing texts in the body of the sent email one under the other -React Native
Trending Discussions on react-native-device-info

QUESTION

Trying to declare variable within useEffect:

Asked 2022-Apr-05 at 13:51

I'm really not sure what I am doing wrong

Please help out...

Is there a better way to access a variable declared within the useEffect?

Thanks

So I have the following code - but I get the error: [TypeError: "setDevice" is read-only]

const [device, setDevice] = useState( '' );
  React.useEffect(() => {
    const device_id = async () => {
      var DeviceInfo = require('react-native-device-info');
      var deviceId = DeviceInfo.getUniqueId();
      const filePath = RNFS.DocumentDirectoryPath + deviceId + "_secret.json";
      if (await RNFS.exists(filePath)){
        RNFS.readFile(filePath, 'utf8')
        .then((contents) => {
          try{
            // setDev = String(contents);
            var JSONObject = JSON.parse(contents);
            console.log(JSONObject['device_id']); 
            setDevice = JSONObject['device_id'];
          }catch(err){
            console.log("Error: ", err);
          }
          
        });
        console.log("FILE EXISTS: " + filePath);
    } else {
      function makeid() {
        var text = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
      
        for (var i = 0; i < 5; i++)
          text += possible.charAt(Math.floor(Math.random() * possible.length));
      
        return text;
      }
      var dev_id = makeid() + deviceId;
      var id = '{"device_id" : "'+dev_id+'"}';
      RNFS.writeFile(filePath, id, 'utf8')
        .then((success) => {
          console.log('FILE WRITTEN!');
          navigation.dispatch(resetReachOutPreferences)
        })
        .catch((err) => {
          console.log(err.message);
        });
      } 
    }
    device_id();
  }, []);
  console.log("ID: " + device);

I've tried useState(null)

ANSWER

Answered 2022-Apr-05 at 13:51

From the React documentation on the State hook:

What does useState return? It returns a pair of values: the current state and a function that updates it.

So in this case, setDevice is a function that can be used to update the value of device (which will be reflected on subsequent renders). Instead of assigning to it, you should call it with the new value as its argument, e.g.:

setDevice(contents);

Source https://stackoverflow.com/questions/71752958

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install react-native-device-info

You can install using 'npm i @scxkkj/react-native-device-info' or download it from GitHub, npm.
You can use react-native-device-info like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the react-native-device-info component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

This module defaults to AndroidX you should configure your library versions similar to this in your android/build.gradle file’s "ext" block. If you need non-AndroidX you will need to use the jetifier package in reverse mode, documentation available with that package.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Consider Popular iOS Libraries
Try Top Libraries by react-native-community
Compare iOS Libraries with Highest Support
Compare iOS Libraries with Highest Quality
Compare iOS Libraries with Highest Security
Compare iOS Libraries with Permissive License
Compare iOS Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.