forked from mateoguzmana/react-native-get-phone-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
85 lines (76 loc) · 2.04 KB
/
Copy pathApp.js
File metadata and controls
85 lines (76 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { Component } from 'react';
import { PermissionsAndroid, StyleSheet, Text, View } from 'react-native';
import RNSimData from "react-native-sim-data";
const initialState = {
data: {}
};
export default class App extends Component {
state = initialState;
componentDidMount() {
this.requestPermissions();
this.getSimData();
}
getSimData() {
const data = RNSimData.getSimInfo();
this.setState({ data });
}
/**
* It will be execute just the first time requesting the permission.
*/
requestPermissions() {
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE)
}
render() {
const {
isNetworkRoaming0,
mcc0,
subscriptionId0,
simSerialNumber0,
carrierName0,
isDataRoaming0,
phoneNumber0,
mnc0,
simSlotIndex0,
deviceId0,
displayName0,
countryCode0
} = this.state.data;
return (
<View style={styles.container}>
<Text style={styles.welcome}>Getting Phone Number with React Native</Text>
<View style={styles.data}>
<Text>isNetworkRoaming: {JSON.stringify(isNetworkRoaming0)}</Text>
<Text>Mcc: {mcc0}</Text>
<Text>subscriptionId: {subscriptionId0}</Text>
<Text>simSerialNumber: {simSerialNumber0}</Text>
<Text>carrierName: {carrierName0}</Text>
<Text>isDataRoaming: {JSON.stringify(isDataRoaming0)}</Text>
<Text>phoneNumber: {phoneNumber0}</Text>
<Text>mnc: {mnc0}</Text>
<Text>simSlotIndex: {simSlotIndex0}</Text>
<Text>deviceId: {deviceId0}</Text>
<Text>displayName: {displayName0}</Text>
<Text>countryCode: {countryCode0}</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
data: {
fontSize: 18,
textAlign: 'center',
margin: 10,
}
});