REACT NATIVE : There is way to identify a device type (smartphone, tablet, laptop)?

[亡魂溺海] 提交于 2020-07-10 08:11:31

问题


There is way to identify a device type (smartphone, tablet, laptop) ? I need to identify a device type as: smartphone, tablet, laptop .. i try to use the "react-native-device-info" api library but dont understand how to identify the 3 specific devices type (smartphone, tablet, laptop) .

So how can i do some code that will gives me if its "Handset"=> Smartphone , if its "unknown"=> Laptop/Computer and it will be saved as well in my async-storage.

import DeviceInfo from 'react-native-device-info';
import AsyncStorage from '@react-native-community/async-storage';

// how can i do some code that will gives me if its "Handset"=> Smartphone , 
//if its "unknown"=> Laptop/Computer 
//and it will be saved as well in my async-storage.

//this some example that i wanna get it works well coz now its not work good

const funct1=  (type) => {
let type = DeviceInfo.getDeviceType();

if type==='Handset'{
  AsyncStorage.setItem('PLATFORM-TYPE', 'Smartphone');
}
if type==='unknown'{
  AsyncStorage.setItem('PLATFORM-TYPE', 'Laptop/Computer');
}
};

回答1:


According to API DOC you can use these APIs to detect the device types:

  • getDeviceType
  • isTablet
  • isEmulator
  • getModel

There are so many APIs to get the device name or any other use-cases. Read the API doc :) Also you cannot detect the laptop as far as I know, React Native does not for on PC.




回答2:


In the mentioned react-native-device-info there is a method getDeviceType() that returns

  • Handset for smartphones,
  • Tablet for tablets,
  • Tv for TV and
  • unknown for everything else (most probably it would be laptops)


来源:https://stackoverflow.com/questions/62752575/react-native-there-is-way-to-identify-a-device-type-smartphone-tablet-lapto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!