[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Request Additional Scopes\n\n| **Warning:**\n|\n| **The Google Sign-In for Android API is outdated and no longer supported.**\n| To ensure the continued security and usability of your app, [migrate your Sign in with\n| Google implementation to Credential Manager](/identity/sign-in/credential-manager-siwg) today. Credential Manager\n| supports passkey, password, and federated identity authentication (such as\n| Sign-in with Google), stronger security, and a more consistent user\n| experience.\n|\n| **For Wear developers:** Credential Manager will be supported in Wear OS\n| 5.1 and later on selected watches. Developers actively supporting Wear OS 3, 4\n| and 5.0 devices with Sign in with Google should continue using Google Sign-in\n| for Android for your Wear applications. Sign in with Google support will be\n| available on Credential Manager APIs for these versions of WearOS at a later\n| date.\n| **Warning:** This page is out of date, refer to [Authorize access to Google user data](/identity/authorization) for the latest best practice.\n\nFor the best user experience, you should request as few scopes as possible when\ninitially signing in users. If your app's core functionality isn't tied to a\nGoogle service, the `GoogleSignInOptions.DEFAULT_SIGN_IN` configuration is often\nall you need at sign-in.\n\nIf your app has features that can make use of Google API data, but are not\nrequired as part of your app's core functionality, you should design your app to\nbe able to gracefully handle cases when API data isn't accessible. For example,\nyou might hide a list of recently saved files when the user hasn't granted Drive\naccess.\n\nYou should request additional scopes that you need to access Google APIs only\nwhen the user performs an action that requires access to a particular API. For\nexample, you might request permission to access the user's Drive only when the\nuser taps a \"Save to Drive\" button for the first time.\n\nBy using this technique, you can avoid overwhelming new users, or confusing\nusers as to why they are being asked for certain permissions.\n\nRequest permissions required by user actions\n--------------------------------------------\n\nWhenever a user performs an action that requires a scope that isn't requested at\nsign-in, call `GoogleSignIn.hasPermissions` to check if the user has already\ngranted the required permissions. If not, call `GoogleSignIn.requestPermissions`\nto launch an activity that requests the additional required scopes from the\nuser.\n\nFor example, if a user performs an action that requires access to their Drive\napp storage, do the following: \n\n if (!GoogleSignIn.hasPermissions(\n GoogleSignIn.getLastSignedInAccount(getActivity()),\n Drive.SCOPE_APPFOLDER)) {\n GoogleSignIn.requestPermissions(\n MyExampleActivity.this,\n RC_REQUEST_PERMISSION_SUCCESS_CONTINUE_FILE_CREATION,\n GoogleSignIn.getLastSignedInAccount(getActivity()),\n Drive.SCOPE_APPFOLDER);\n } else {\n saveToDriveAppFolder();\n }\n\nIn your activity's `onActivityResult` callback, you can check if the required\npermissions were successfully acquired, and if so, carry out the user action. \n\n @Override\n public void onActivityResult(int requestCode, int resultCode, Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n if (resultCode == Activity.RESULT_OK) {\n if (RC_REQUEST_PERMISSION_SUCCESS_CONTINUE_FILE_CREATION == requestCode) {\n saveToDriveAppFolder();\n }\n }\n }\n\nYou can also pass a `GoogleSignInOptionsExtension` to `hasPermissions` and\n`requestPermissions` to check for and acquire a set of permissions more\nconveniently."]]