تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
ستساعدك الأمثلة التالية في تنفيذ معرّف العنصر في أحد عملاء Android. تجدر الإشارة إلى أنّ هذه الأمثلة تستخدِم نطاق GCM، وهو مفيد فقط
لأغراض العرض لأنّه تم
إيقاف Google Cloud Messaging نهائيًا.
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);
إدارة الرموز المميّزة وأرقام تعريف النماذج
يتيح لك رقم تعريف المثيل حذف الرموز المميّزة وإعادة تحميلها.
يمكنك أيضًا حذف معرّف المثيل نفسه، بما في ذلك كل علامات الاعتماد المرتبطة به. في المرة التالية التي تتصل فيها بـ getInstance()، ستحصل على
معرّف مثيل جديد:
تبدأ خدمة Instance ID عمليات إعادة الاتصال بشكل دوري (على سبيل المثال،
كل 6 أشهر)، وتطلب من تطبيقك تحديث الرموز المميّزة. وقد يؤدي أيضًا إلى
بدء عمليات معاودة الاتصال في الحالات التالية:
هناك مشاكل أمنية، مثل مشاكل طبقة مأخذ التوصيل الآمنة أو المنصة.
لم تعُد معلومات الجهاز صالحة، مثل الاحتفاظ بنسخة احتياطية من البيانات واستعادتها.
تتأثر خدمة رقم تعريف النسخة بخلاف ذلك.
نفِّذ خدمة مستمع رقم تعريف المثيل في تطبيقك لتلقّي طلبات إعادة الاتصال التالية:
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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,["# Android Implementation\n\nThe 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---------------------------\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------------------\n\nThe following line of code returns an Instance ID: \n\n String iid = InstanceID.getInstance(context).getId();\n\nGenerate a token\n----------------\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------------------------------\n\nInstance ID lets you delete and refresh tokens.\n\n### Delete 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\n### Refresh 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"]]