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
2 Answers
Reset to default 5In the mentioned react-native-device-info
there is a method getDeviceType()
that returns
Handset
for smartphones,Tablet
for tablets,Tv
for TV andunknown
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条)