我在使用 flt_telephony_info flutter 插件获取用户电话号码时遇到问题,即使在 AndroidManifest.xml 中添加了必要的权限,该值仍然返回 null。按照下面的代码。
//AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
//main.dart
TelephonyInfo _info;
Future<void> getTelephonyInfo() async {
TelephonyInfo info;
try {
info = await FltTelephonyInfo.info;
} on PlatformException {}
if (!mounted) return;
setState(() {
_info = info;
});
}
@override
void initState() {
super.initState();
getTelephonyInfo();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Test'),
),
body: Center(
child: Text('Phone Number: ${_info?.line1Number}\n'),
),
),
);
}
}
这是回报:
E/MethodChannel#bughub.dev/flt_telephony_info(32179):无法处理方法调用 E/MethodChannel#bughub.dev/flt_telephony_info(32179): java.lang.SecurityException: getImeiForSlot: 用户10259不符合访问设备标识符的要求。 E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.os.Parcel.createException(Parcel.java:2071) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.os.Parcel.readException(Parcel.java:2039) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.os.Parcel.readException(Parcel.java:1987) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 com.android.internal.telephony.ITelephony$Stub$Proxy.getImeiForSlot(ITelephony.java:10945) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.telephony.TelephonyManager.getImei(TelephonyManager.java:1815) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.telephony.TelephonyManager.getImei(TelephonyManager.java:1776) E/MethodChannel#bughub.dev/flt_telephony_info(32179):在 dev.bughub.flt_telephony_info.FltTelephonyInfoPlugin.onMethodCall(FltTelephonyInfoPlugin.kt:89) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.os.MessageQueue.next(MessageQueue.java:343) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.os.Looper.loop(Looper.java:188) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 android.app.ActivityThread.main(ActivityThread.java:7604) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) E/MethodChannel#bughub.dev/flt_telephony_info(32179): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
有人可以帮我吗?