Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 键入编辑文本时获取电子邮件建议?_Android_Settings - Fatal编程技术网

Android 键入编辑文本时获取电子邮件建议?

Android 键入编辑文本时获取电子邮件建议?,android,settings,Android,Settings,我正在我的应用程序的注册屏幕上工作。我需要在打字时收到电子邮件建议。它不需要与Gmail Id帐户同步。它应该获得我正在使用的电子邮件id作为帐户,我们可以在帐户设置中看到它。用户应该在他的android手机中拥有Gmail帐户 import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; /** * This class uses the Ac

我正在我的应用程序的注册屏幕上工作。我需要在打字时收到电子邮件建议。它不需要与Gmail Id帐户同步。它应该获得我正在使用的电子邮件id作为帐户,我们可以在帐户设置中看到它。

用户应该在他的android手机中拥有Gmail帐户

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;

/**
 * This class uses the AccountManager to get the primary email address of the
 * current user.
 */
public class UserEmailFetcher {

  static String getEmail(Context context) {
    AccountManager accountManager = AccountManager.get(context); 
    Account account = getAccount(accountManager);

    if (account == null) {
      return null;
    } else {
      return account.name;
    }
  }

  private static Account getAccount(AccountManager accountManager) {
    Account[] accounts = accountManager.getAccountsByType("com.google");
    Account account;
    if (accounts.length > 0) {
      account = accounts[0];      
    } else {
      account = null;
    }
    return account;
  }
}
明显地

  <uses-permission android:name="android.permission.GET_ACCOUNTS" />

资料来源: