问题
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
Handsetfor smartphones,Tabletfor tablets,Tvfor TV andunknownfor 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