Flutter获取电话号码

Gre*_*Eye 2 dart flutter

如何获取运行应用程序的当前手机的手机号码?

例如这个插件?直接获取手机号码会很酷.

https://github.com/flutter/plugins/pull/329

Rod*_*voi 9

重要提示:请注意,该mobile_number插件需要非常特殊的权限才能拨打电话。
sms_autofill 根本不询问任何权限。像这样使用它:

  @override
  void initState() {
    super.initState();
    Future<void>.delayed(const Duration(milliseconds: 300), _tryPasteCurrentPhone);
  }

  Future _tryPasteCurrentPhone() async {
    if (!mounted) return;
    try {
      final autoFill = SmsAutoFill();
      final phone = await autoFill.hint;
      if (phone == null) return;
      if (!mounted) return;
      _textController.value = phone;
    } on PlatformException catch (e) {
      print('Failed to get mobile number because of: ${e.message}');
    }
  }
Run Code Online (Sandbox Code Playgroud)


小智 8

dart 酒吧中的这个图书馆似乎可以满足您的需求。检查下面链接的包:

https://pub.dev/packages/sms_autofill

PhoneFieldHint [仅限安卓]

final SmsAutoFill _autoFill = SmsAutoFill();
final completePhoneNumber = await _autoFill.hint;
Run Code Online (Sandbox Code Playgroud)

  • 这在发布模式下不起作用。 (2认同)

Ren*_*ene 7

使用原生Android/iOS代码无法做到这一点,因此也不会在Flutter中执行此操作.例如,WhatsApp只是要求用户输入他们的号码,然后发送带有验证码的短信.