在 React Native Android 应用程序中获取 Android 设备的主要电子邮件地址

Get Android device's primary email address in React Native Android App

是否有任何好的反应本机库来获取 android 设备的主要电子邮件地址。 有一个 Whosebug 问题要用 native android (link) 得到它。我需要将它包含在 React Native android app.

更新:我可以通过 android 本机的以下方法获取电子邮件地址。现在我需要在 React Native 中实现它。

权限:

使用权限android:name="android.permission.GET_ACCOUNTS"

方法:

  String emailAddress = "";
    private String getEmail() {
        int i = 0;
        try {
            Account[] accounts = AccountManager.get(this).getAccountsByType(
                    "com.google");
            for (Account account : accounts) {
                if (i > 0)
                    sGoogleId = account.name;
                else
                    sGoogleId = account.name;
                i++;

            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return emailAddress;
    }

我可以通过使用 React Native Native 模块来解决这个问题。设备应至少有一个 google 帐户。由于处理请求需要一些时间,因此需要使用承诺 (androidManager.getAccounts().then(){}.Done(){}) 进行收集。