This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 蜂窝网络 iconExpo 蜂窝网络

提供有关用户的蜂窝服务提供商信息的 API。

Android
iOS
Web
Included in Expo Go
Recommended version:
~58.0.2

expo-cellular 提供关于用户手机服务提供商的信息,比如它的唯一标识符和蜂窝连接类型。

安装

🌐 Installation

Terminal
- npx expo install expo-cellular
- yarn expo install expo-cellular
- pnpm expo install expo-cellular
- bun expo install expo-cellular

If you are installing this in an existing React Native app, make sure to install expo in your project.

配置

🌐 Configuration

Are you using this library in an existing React Native app?

如果你没有使用连续原生生成(CNG),或者你正在手动使用原生 android 项目,那么你需要在项目的 AndroidManifest.xml 中添加 android.permission.READ_PHONE_STATE 权限。这个权限用于 TelephonyManager。

🌐 If you're not using Continuous Native Generation (CNG) or you're using a native android project manually, then you need to add android.permission.READ_PHONE_STATE permission to your project's AndroidManifest.xml. This permission is used for TelephonyManager.

android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

该库不需要更高风险的 READ_PRIVILEGED_PHONE_STATE 权限。

🌐 This library does not require the more risky READ_PRIVILEGED_PHONE_STATE permission.

应用接口

🌐 API

import * as Cellular from 'expo-cellular';

No API data file found, sorry!

错误代码

🌐 Error codes

代码描述
ERR_CELLULAR_GENERATION_UNKNOWN_NETWORK_TYPE无法获取网络类型或未连接到蜂窝网络

权限

🌐 Permissions

安卓

🌐 Android

你必须将以下权限添加到你的 app.json 中的 expo.android.permissions 数组里。

🌐 You must add the following permissions to your app.json inside the expo.android.permissions array.

Android permissionDescription

READ_PHONE_STATE

Allows read only access to phone state, including the current cellular network information, the status of any ongoing calls, and a list of any PhoneAccounts registered on the device.

iOS

无需权限。

🌐 No permissions required.