您的位置:首页 > 编程语言 > Go语言

客制化开机向导符合Google认证要求

2016-07-07 17:06 411 查看

客制化开机向导符合Google认证要求

[DESCRIPTION]

从KK版本开始,Google允许OEM在预置GMS项目中使用非GMS中的开机向导在预置GMS项目中如果使用三方开机向导,Google对此有一些认证要求,需要在开机向导中加入Google账户登录等Google服务功能界面

[SOLUTION]

首先确认为KK版本,并已预置GMS核心组件

以下是添加Google账户的接口代码:

AccountManager acctMgr = AccountManager.get(this);

Bundle options = new Bundle();

options.putBoolean("allowSkip", true);

options.putBoolean("firstRun", true);

options.putBoolean("setupWizard", true);

AccountManagerFuture futBundle = acctMgr.addAccount(

"com.google", // Google’s account type.

null, // The authTokenType is not relevant to Google.

null, // No requiredFeatures.

options,

this, // The Activity context.

mCallback, // Simplest just to handle an error intent directly.

null); // No callback implies no handler.

try {

Intent googleSignInWorkFlow =

futBundle.getResult().getParcelable(AccountManager.KEY_INTENT);

this.startActivityForResult(googleSignInWorkFlow, REQUEST_CODE);

} catch (Exception e) {

// AccountManager.addAccount throws various exceptions.

// Left to the implementer.

}

将以上代码加入到客制化开机向导合适位置,即可通过AccountManager的addAccount()唤起Google账户登录(注册/跳

过)界面

ps: 您可以添加addAccount()的callBack方法来handle此方法返回值判断用户操作行为(区分返回或者下一步)

callback方法可以参考如下写法:

private final AccountManagerCallback<Bundle> mCallback = new

AccountManagerCallback<Bundle>() {

@Override

public void run(AccountManagerFuture<Bundle> future) {

Log.i("MTKdebugGoo", "mCallback added" );

try {

Bundle bundle = future.getResult();

Log.i("mtkdebugGoo", "account added: " + bundle);

if(bundle.toString().contains("accountType=com.google"))

setResult(NEXT_ADD);

else

setResult(NEXT);

} catch (OperationCanceledException e) {

Log.v("mtkdebugGoo", "addAccount was canceled");

setResult(BACK);

mAddAccount = false;

} catch (IOException e) {

Log.v("mtkdebugGoo", "addAccount failed1: " + e);

} catch (AuthenticatorException e) {

Log.v("mtkdebugGoo", "addAccount failed2: " + e);

} finally {

finish();

}

}

};

如此即可满足Google对开机向导认证要求

如果您还需要添加Google开机向导中其它服务如分享位置信息等功能,可以继续将如下code添加到开机向导合适位置:

Intent intent = new Intent();

intent.setPackage("com.google.Android.setupwizard");

intent.setClassName("com.google.android.setupwizard",

"com.google.android.setupwizard.LocationSharingActivity");

startActivityForResult(intent, REQUEST_CODE);

谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息