Google+ Sign-in for Android - Google Permissions Activity Result Codes

元气小坏坏 提交于 2019-12-06 12:11:12

Well, after fighting a while with this I think I found a solution. I don't know if it's the right way to do it, but I thought I should share it, so here it goes.

we have the onActivityresult method that the activity doing the login/sign in should implement.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     (...)
}

What I thought (after a thinking a while, and later confirmed) was that the Intent data parameter should have some kind of clue or info about what kind of error or result is being returned. After inspecting it little bit I found that in the case of the user denying the permissions for the app, this intent had an Extra String with key Error and value UserCancel. So that's what I ended up using to distinguish one case from the other. Hope it helps!

   data.getExtraString("Error"); // This should have the value "UserCancel" when the user    
                                 // refused to give the permissions required by the app. 

Please note that the data intent may not always offer this ExtraString, and in fact may be null for some calls of onActityResult, so you should check if (data != null) before using this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!