تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يتضمّن تطبيق Gmail على Android
مزوّد محتوى
يمكن للمطوّرين الخارجيين استخدامه لاسترداد معلومات التصنيفات، مثل الاسم وعدد الرسائل غير المقروءة، والبقاء على اطّلاع دائم على التغييرات التي تطرأ على هذه المعلومات. على سبيل المثال، يمكن أن يعرض تطبيق أو أداة عدد الرسائل غير المقروءة في صندوق وارد حساب معيّن.
قبل استخدام موفّر المحتوى هذا، استدعِ طريقة
GmailContract.canReadLabels(Context)
لتحديد ما إذا كان إصدار تطبيق Gmail الذي يستخدمه المستخدم يتيح تنفيذ عمليات البحث هذه.
العثور على حساب Gmail صالح لإجراء طلب بحث
يجب أن يعثر التطبيق أولاً على عنوان البريد الإلكتروني لحساب Gmail صالح من أجل طلب معلومات التصنيف. باستخدام إذن
GET_ACCOUNTS،
يمكن أن يعرض
AccountManager
المعلومات التالية:
// Get the account list, and pick the first onefinalStringACCOUNT_TYPE_GOOGLE="com.google";finalString[]FEATURES_MAIL={"service_mail"};AccountManager.get(this).getAccountsByTypeAndFeatures(ACCOUNT_TYPE_GOOGLE,FEATURES_MAIL,newAccountManagerCallback(){@Overridepublicvoidrun(AccountManagerFuturefuture){Account[]accounts=null;try{accounts=future.getResult();if(accounts!=null&&accounts.length>0){StringselectedAccount=accounts[0].name;queryLabels(selectedAccount);}}catch(OperationCanceledExceptionoce){// TODO: handle exception}catch(IOExceptionioe){// TODO: handle exception}catch(AuthenticatorExceptionae){// TODO: handle exception}}},null/*handler*/);
طلب البحث من موفّر المحتوى
بعد اختيار عنوان بريد إلكتروني، يمكنك الحصول على معرّف موارد منتظم (URI) ContentProvider لإجراء طلب بحث. لقد وفّرنا فئة بسيطة باسم
GmailContract.java
لإنشاء عنوان URI وتحديد الأعمدة التي يتم عرضها.
يمكن لأي تطبيق طلب البحث عن معرّف الموارد المنتظم هذا مباشرةً، أو الأفضل من ذلك، استخدام
CursorLoader
للحصول على مؤشر يتضمّن معلومات عن جميع التصنيفات في الحساب:
باستخدام البيانات في هذا المؤشر، يمكنك بعد ذلك الاحتفاظ بقيمة معرّف الموارد المنتظم (URI) في العمود GmailContract.Labels.URI للاستعلام عن التغييرات في تصنيف واحد ومراقبتها.
يمكن أن تختلف قيمة NAME للتصنيفات المحدّدة مسبقًا حسب اللغة، لذا لا تستخدِم GmailContract.Labels.NAME. بدلاً من ذلك، يمكنك تحديد التصنيفات المحدّدة مسبقًا، مثل "البريد الوارد" أو "الرسائل المرسَلة" أو "المسودّات"، بشكل آلي باستخدام قيمة السلسلة في العمود GmailContract.Labels.CANONICAL_NAME:
// loop through the cursor and find the Inboxif(labelsCursor!=null){finalStringinboxCanonicalName=GmailContract.Labels.LabelCanonicalName.CANONICAL_NAME_INBOX;finalintcanonicalNameIndex=labelsCursor.getColumnIndexOrThrow(GmailContract.Labels.CANONICAL_NAME);while(labelsCursor.moveToNext()){if(inboxCanonicalName.equals(labelsCursor.getString(canonicalNameIndex))){// this row corresponds to the Inbox}}}
تاريخ التعديل الأخير: 2025-08-29 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-29 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Android content provider for Gmail\n\nThe Android Gmail app includes a\n[content provider](https://developer.android.com/guide/topics/providers/content-providers)\nthat third party developers can use to retrieve label information like name and\nunread count, and stay updated as that information changes. For example, an app\nor widget could display the unread count of a specific account's inbox.\n| **Note:** This content provider is supported in versions after 2.3.6 (Froyo/Gingerbread) and 4.0.5 (Honeycomb/ICS).\n\nBefore using this content provider, call the\n[`GmailContract.canReadLabels(Context)`](/workspace/gmail/android/com/google/android/gm/contentprovider/GmailContract#public-static-boolean-canreadlabels-context-c)\nmethod to determine whether the user's version of the Gmail app supports these\nqueries.\n\nFind a valid Gmail account to query\n-----------------------------------\n\nAn app must first find the email address of a valid Gmail account to query for\nlabel information. With the\n[`GET_ACCOUNTS`](http://developer.android.com/reference/android/Manifest.permission.html#GET_ACCOUNTS)\npermission, the\n[`AccountManager`](http://developer.android.com/reference/android/accounts/AccountManager.html)\ncan return this information: \n\n // Get the account list, and pick the first one\n final String ACCOUNT_TYPE_GOOGLE = \"com.google\";\n final String[] FEATURES_MAIL = {\n \"service_mail\"\n };\n AccountManager.get(this).getAccountsByTypeAndFeatures(ACCOUNT_TYPE_GOOGLE, FEATURES_MAIL,\n new AccountManagerCallback() {\n @Override\n public void run(AccountManagerFuture future) {\n Account[] accounts = null;\n try {\n accounts = future.getResult();\n if (accounts != null && accounts.length > 0) {\n String selectedAccount = accounts[0].name;\n queryLabels(selectedAccount);\n }\n\n } catch (OperationCanceledException oce) {\n // TODO: handle exception\n } catch (IOException ioe) {\n // TODO: handle exception\n } catch (AuthenticatorException ae) {\n // TODO: handle exception\n }\n }\n }, null /* handler */);\n\nQuery the content provider\n--------------------------\n\nWith an email address selected, you can then obtain a\n[`ContentProvider`](http://developer.android.com/guide/topics/providers/content-provider-basics.html)\nURI to query against. We've provided a simple class called\n[`GmailContract.java`](/workspace/gmail/android/com/google/android/gm/contentprovider/GmailContract)\nto construct the URI and define the columns returned.\n\nAn app can query this URI directly --- or better yet, use a\n[`CursorLoader`](http://developer.android.com/reference/android/content/CursorLoader.html)\n--- to obtain a Cursor with information for all labels on an account: \n\n Cursor labelsCursor = getContentResolver().query(GmailContract.Labels.getLabelsUri(selectedAccount), null, null, null, null);\n\nWith the data in this cursor, you can then persist the URI value in the\n`GmailContract.Labels.URI` column to query and watch for changes on a\nsingle label.\n\nThe `NAME` value for pre-defined labels can vary by locale, so don't\nuse `GmailContract.Labels.NAME`. Instead, you can programmatically\nidentify pre-defined labels like Inbox, Sent or Drafts using the String value in\nthe `GmailContract.Labels.CANONICAL_NAME` column: \n\n // loop through the cursor and find the Inbox\n if (labelsCursor != null) {\n final String inboxCanonicalName = GmailContract.Labels.LabelCanonicalName.CANONICAL_NAME_INBOX;\n final int canonicalNameIndex = labelsCursor.getColumnIndexOrThrow(GmailContract.Labels.CANONICAL_NAME);\n while (labelsCursor.moveToNext()) {\n if (inboxCanonicalName.equals(labelsCursor.getString(canonicalNameIndex))) {\n // this row corresponds to the Inbox\n }\n }\n }\n\nFor more help, read\n[Content provider basics](https://developer.android.com/guide/topics/providers/content-provider-basics.html)\n\nReview an example\n-----------------\n\nTo see an example of this content provider in action,\n[download a sample app](/static/workspace/gmail/android/android-gmail-api-sample.tar.gz)."]]