为Android C2DM选择Google帐户

时间:2011-01-04 23:13:49

标签: android android-c2dm


我有C2DM服务的问题。鉴于设备上有多个Google帐户,我希望我的应用程序选择其中一个帐户注册到C2DM(您知道使用首选项)。有可能吗?

提前致谢

2 个答案:

答案 0 :(得分:3)

是的,有可能。查看Chrome to Phone应用程序(http://code.google.com/p/chrometophone/)。在那里,他们从String数组中构建一个帐户列表,如下所示:

    ArrayList<String> accountNames = new ArrayList<String>();
    Account[] accounts = AccountManager.get(this).getAccounts();
    for (Account account : accounts) {
        if (account.type.equals("com.google")) {
            accountNames.add(account.name);
        }
    }

    String[] result = new String[accountNames.size()];
    accountNames.toArray(result);

答案 1 :(得分:0)

在考虑之后我觉得它不会这样做。所有C2DM需求都是“现有连接”,我认为无论有多少谷歌帐户,只有一个连接。