【问题标题】:Configuring the google account programmatically in Android在 Android 中以编程方式配置 google 帐户
【发布时间】:2015-03-12 16:02:26
【问题描述】:

我需要一些帮助,我正在尝试在 android 后面配置 google 帐户,主要思想是不要使用向导来配置 google 帐户,我需要通过代码来执行此操作,我正在搜索,但不要成功,我试图做的唯一方法是以下,但我相信这只是让我当前的应用程序访问我正在尝试使用的帐户的一种方法,但仍然没有成功

@Override
public void onClick(View v) {
    try{
        AccountManager mgr = AccountManager.get(this);
        Account acc = new Account("sexo@gmail.com", "com.google");
        if(mgr.addAccountExplicitly(acc, "pass", new Bundle())) {
            Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_LONG);
        }
    }catch(Exception e){
        Log.d("test", e.getMessage());
        Log.d("test", e.toString());
        e.getStackTrace();
        e.printStackTrace();
    }

这是我使用的清单

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.actteste"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS"/>
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />    
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permaission.INTERACT_ACROSS_USERS_FULL"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:installLocation="internalOnly">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name="com.company.demo.account.AuthenticatorService" android:exported="false">
        <intent-filter>
            <action android:name="android.accounts.AccountAuthenticator"/>
        </intent-filter>
        <meta-data
            android:name="android.accounts.AccountAuthenticator"
            android:resource="@xml/authenticator"/>
        </service>
    </application>

</manifest>

我尝试创建服务并在清单中引用

    <?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
                   android:accountType="com.company.demo.account.DEMOACCOUNT"
                   android:icon="@drawable/ic_launcher"
                   android:smallIcon="@drawable/ic_launcher"
                   android:label="qualquer"/>

【问题讨论】:

    标签: java android android-layout android-activity


    【解决方案1】:

    您不能使用帐户管理器在 Google 服务器上设置新帐户。只能用于登录。

    Android 中的设置应用程序也没有可用于设置新帐户的 API。唯一真正的方法是对他们的应用程序代码进行逆向工程并尝试注入值。它不聪明,原因如下:

    所有这些都是为了客户安全和 Google 保护而设计的。以自动方式执行此操作时,客户不同意条款和条件,并且创建的帐户对设备或设备本身的用户信息具有危险的访问权限。

    如果这是 100% 必需的,我建议您让设备与您拥有的服务器通信,该服务器处理与 Google 的协商并相应地提醒用户。这不是您可能想听到的,但这不是一条可取的途径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 2014-01-26
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多