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

There is way to identify a device type (smartphone, tablet, laptop) ?I need toidentify a device type

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-munity/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');
}
};

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-munity/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');
}
};
Share Improve this question edited Jul 6, 2020 at 10:31 shira asked Jul 6, 2020 at 8:59 shirashira 3945 silver badges21 bronze badges 1
  • Have you solved this, yet? – Shahnawaz Hossan Commented Jul 6, 2020 at 12:03
Add a ment  | 

2 Answers 2

Reset to default 5

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)

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745375699a4624988.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信