【问题标题】:Get Phone Brand in React Native app built using Expo在使用 Expo 构建的 React Native 应用程序中获取电话品牌
【发布时间】:2019-07-26 19:22:17
【问题描述】:

我正在使用 Expo 和 React Native 构建一个应用程序。我处于需要获取一些设备信息的情况,例如:手机品牌、手机型号,以及适用于 Android 和 iOS 的 Mac 地址(如果可能)。在这里我只要求电话品牌。 我曾尝试使用 Expo Constants API,但它只返回 Device Name(例如三星 Galaxy A7 的 SM-A750GN)。我想要的是获得像“三星”这样的品牌。

有什么方法可以在不退出世博会的情况下获得品牌?有这个库 'react-native-device-info' 但我想我必须使用 react-native 链接弹出和链接。

【问题讨论】:

    标签: react-native expo


    【解决方案1】:

    如果设备名称总是返回相同的格式,以前 2 个字母开头作为品牌的缩写,您可以编写简单的 switch 语句来获取品牌。

    我想这对你来说是最好的选择。

    let deviceName = 'SM-A750GN' 
    let brand = deviceName.slice(0,2); // this will give you SM
    let realBrand = ''
    
    switch(brand) {
      case "SM":
        realBrand = "Samsung";
        break;
      case "AP":
        realBrand = "Apple";
        break;
      case "LG":
        realBrand = "LG";
        break;
      default:
        realBrand = "Undefined";
    }
    

    【讨论】:

    • 这不是真的,Contants 包上的 deviceName 属性返回设备名称。可能是“JohnDoe”,因为用户有权在 android 中更改设备名称。
    • @rafaelmorais 如果你查看源代码 public String getDeviceName() { return Build.MODEL; } 函数返回手机型号,用户不能更改。你可以在谷歌网站上找到所有可能的模型丢失。 support.google.com/googleplay/answer/1727131?hl=en
    猜你喜欢
    • 1970-01-01
    • 2017-12-09
    • 2020-12-06
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 1970-01-01
    • 2021-06-17
    相关资源
    最近更新 更多