String authorizedEntity = PROJECT_ID; // Project id from Google Developer Console String scope = "GCM"; // e.g. communicating using GCM, but you can use any // URL-safe characters up to a maximum of 1000, or // you can also leave it blank. String token = InstanceID.getInstance(context).getToken(authorizedEntity,scope);
[[["이해하기 쉬움","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"]],["최종 업데이트: 2025-08-17(UTC)"],[[["\u003cp\u003eThis documentation provides examples of how to implement Instance ID in an Android client using the Google Play services SDK.\u003c/p\u003e\n"],["\u003cp\u003eYou can get an Instance ID, generate tokens using your Project ID, and manage these tokens by deleting or refreshing them.\u003c/p\u003e\n"],["\u003cp\u003eInstance ID service may initiate callbacks for token refresh due to security issues, device information changes, or other service-related events.\u003c/p\u003e\n"],["\u003cp\u003eTo handle token refresh callbacks, implement the Instance ID listener service and configure it in your Android Manifest file.\u003c/p\u003e\n"]]],[],null,["The following examples will help you implement Instance ID in an Android\nclient. Note that these examples use the GCM scope, which is useful only\nfor demonstration purposes because\n[Google Cloud Messaging](/cloud-messaging/android/client) has been\nretired from use.\n\nSet Up Google Play Services\n\nTo write your client application, use the Google Play services SDK,\nas described in [Set up Google Play\nServices SDK](http://developer.android.com/google/play-services/setup.html). The Play Services Library includes the Instance ID library.\n\nGet an Instance ID\n\nThe following line of code returns an Instance ID: \n\n String iid = InstanceID.getInstance(context).getId();\n\nGenerate a token\n\nGenerating tokens requires a Project ID generated by the\n[Google Developers Console](https://console.developers.google.com/project). \n\n String authorizedEntity = PROJECT_ID; // Project id from Google Developer Console\n String scope = \"GCM\"; // e.g. communicating using GCM, but you can use any\n // URL-safe characters up to a maximum of 1000, or\n // you can also leave it blank.\n String token = InstanceID.getInstance(context).getToken(authorizedEntity,scope);\n\nManage tokens and Instance IDs\n\nInstance ID lets you delete and refresh tokens.\n\nDelete tokens and Instance IDs \n\n String authorizedEntity = PROJECT_ID;\n String scope = \"GCM\";\n InstanceID.getInstance(context).deleteToken(authorizedEntity,scope);\n\nYou can also delete the Instance ID itself, including all associated\ntokens. The next time you call `getInstance()` you will get a new\nInstance ID: \n\n InstanceID.getInstance(context).deleteInstanceID();\n String newIID = InstanceID.getInstance(context).getId();\n\n| **Note:** If your app used tokens that were deleted by `deleteInstanceID`, your app will need to generate replacement tokens.\n\nRefresh tokens\n\nThe Instance ID service initiates callbacks periodically (for example,\nevery 6 months), requesting that your app refreshes its tokens. It may also\ninitiate callbacks when:\n\n- There are security issues; for example, SSL or platform issues.\n- Device information is no longer valid; for example, backup and restore.\n- The Instance ID service is otherwise affected.\n\nImplement the Instance ID listener service in your app to receive these\ncallbacks: \n\n public class MyInstanceIDService extends InstanceIDListenerService {\n public void onTokenRefresh() {\n refreshAllTokens();\n }\n\n private void refreshAllTokens() {\n // assuming you have defined TokenList as\n // some generalized store for your tokens\n ArrayList\u003cTokenList\u003e tokenList = TokensList.get();\n InstanceID iid = InstanceID.getInstance(this);\n for(tokenItem : tokenList) {\n tokenItem.token =\n iid.getToken(tokenItem.authorizedEntity,tokenItem.scope,tokenItem.options);\n // send this tokenItem.token to your server\n }\n }\n };\n\nYou must also configure this service in the Manifest file for the project: \n\n \u003cservice android:name=\".MyInstanceIDService\" android:exported=\"false\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"com.google.android.gms.iid.InstanceID\"/\u003e\n \u003c/intent-filter\u003e\n \u003c/service\u003e"]]