تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
في الإصدار 11 من نظام التشغيل Android (المستوى 30 من حزمة تطوير البرامج (SDK)) والإصدارات الأحدث، يمكن للتطبيقات استخدام الغرض
android.provider.Settings.ACTION_WIFI_ADD_NETWORKS
لتوجيه المستخدم خلال عملية إضافة شبكة واحدة أو أكثر من الشبكات المحفوظة الجديدة أو إعدادات
Passpoint. تعمل واجهة برمجة التطبيقات أيضًا كما هي لتعديل الإعدادات المحفوظة الحالية.
لحفظ شبكة أو إعدادات Passpoint، اتّبِع الخطوات التالية:
أنشئ ACTION_WIFI_ADD_NETWORKS نية.
أنشئ إعدادًا واحدًا أو أكثر باستخدام
WifiNetworkSuggestion.Builder.
يُرجى العِلم أنّه على الرغم من استخدامك WifiNetworkSuggestion، لا ترتبط واجهة برمجة التطبيقات هذه الخاصة بـ Intent API بواجهة Suggestion API.
أنشِئ قائمة مصفوفة قابلة للتسلسل من الإعدادات وأرفِقها بـ
intent باستخدام
EXTRA_WIFI_NETWORK_LIST
إضافية.
إذا كانت قيمة resultCode هي RESULT_OK، ستتضمّن البيانات Intent الإضافات EXTRA_WIFI_NETWORK_RESULT_LIST التي تحتوي على مصفوفة من رموز النتائج تشير إلى ما إذا تم حفظ الإعدادات الفردية بنجاح. في ما يلي رموز النتائج المحتمَلة:
في حال نجاح الطلب، ستفعّل المنصة عملية ربط بإحدى الشبكات التي تم حفظها حديثًا.
عيّنة التعليمات البرمجية
يوضّح نموذج الرمز البرمجي التالي كيفية حفظ إعدادات شبكة أو Passpoint.
classMainActivity:AppCompatActivity(){overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)...}funstartOperation(){valsuggestions=ArrayList<WifiNetworkSuggestion>()// WPA2 configurationsuggestions.add(WifiNetworkSuggestion.Builder().setSsid("test111111").setWpa2Passphrase("test123456").build())// Open configurationsuggestions.add(WifiNetworkSuggestion.Builder().setSsid("test222222").build())// Passpoint configurationvalconfig=PasspointConfiguration()config.credential=Credential().apply{realm="realm.example.com"simCredential=Credential.SimCredential().apply{eapType=18imsi="123456*"}}config.homeSp=HomeSp().apply{fqdn="test1.example.com"friendlyName="Some Friendly Name"}suggestions.add(WifiNetworkSuggestion.Builder().setPasspointConfig(config).build())// Create intentvalbundle=Bundle()bundle.putParcelableArrayList(EXTRA_WIFI_NETWORK_LIST,suggestions)valintent=Intent(ACTION_WIFI_ADD_NETWORKS)intent.putExtras(bundle)// Launch intentstartActivityForResult(intent,0)}overridefunonActivityResult(requestCode:Int,resultCode:Int,data:Intent?){super.onActivityResult(requestCode,resultCode,data)if(resultCode==RESULT_OK){// user agreed to save configurations: still need to check individual resultsif(data!=null && data.hasExtra(EXTRA_WIFI_NETWORK_RESULT_LIST)){for(codeindata.getIntegerArrayListExtra(EXTRA_WIFI_NETWORK_RESULT_LIST)){when(code){ADD_WIFI_RESULT_SUCCESS->
...// Configuration saved or modifiedADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED->
...// Something went wrong - invalid configurationADD_WIFI_RESULT_ALREADY_EXISTS->
...// Configuration existed (as-is) on device, nothing changedelse->
...// Other errors}}}}else{// User refused to save configurations}}}
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["On Android 11 (SDK level 30) and higher, apps can use the\n[`android.provider.Settings.ACTION_WIFI_ADD_NETWORKS`](/reference/android/provider/Settings#ACTION_WIFI_ADD_NETWORKS)\nintent to guide the user through adding one or more new saved networks or\nPasspoint configurations. The API also works as-is to modify existing saved\nconfigurations.\n| **Note:** This API is the closest in functionality to the deprecated `WifiManager.addNetwork(WifiConfiguration config)` API, in that the resulting configuration is added to the user-facing and managed saved network and subscription list.\n\nTo save a network or Passpoint configuration, do the following:\n\n1. Create an `ACTION_WIFI_ADD_NETWORKS` intent.\n\n2. Create one or more configurations using\n [`WifiNetworkSuggestion.Builder`](/reference/android/net/wifi/WifiNetworkSuggestion.Builder).\n Note that even though you use a `WifiNetworkSuggestion`, this Intent API is\n not related to the [Suggestion API](/develop/connectivity/wifi-suggest).\n\n3. Create a parcelable array list of the configurations and attach it to the\n intent with the\n [`EXTRA_WIFI_NETWORK_LIST`](/reference/android/provider/Settings#EXTRA_WIFI_NETWORK_LIST)\n extra.\n\n4. Execute\n [`Activity.startActivityForResult()`](/reference/android/app/Activity#startActivityForResult(android.content.Intent,%20int)),\n passing in the intent.\n\n5. Listen for the result using the\n [`Activity.onActivityResult()`](/reference/android/app/Activity#onActivityResult(int,%20int,%20android.content.Intent))\n callback.\n\n The `resultCode` can be one of the following:\n - [`Activity.RESULT_OK`](/reference/android/app/Activity#RESULT_OK): indicating that the user accepted the proposed networks and saved them.\n - [`Activity.RESULT_CANCELED`](/reference/android/app/Activity#RESULT_CANCELED): indicating that the user rejected the proposed networks.\n\n If the `resultCode` is `RESULT_OK`, then the data `Intent` contains the\n [`EXTRA_WIFI_NETWORK_RESULT_LIST`](/reference/android/provider/Settings#EXTRA_WIFI_NETWORK_RESULT_LIST)\n extra, which contains an array of result codes indicating whether individual\n configurations were saved successfully. The possible result codes are:\n - [`ADD_WIFI_RESULT_SUCCESS`](/reference/android/provider/Settings#ADD_WIFI_RESULT_SUCCESS): configuration added or successfully updated.\n - [`ADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED`](/reference/android/provider/Settings#ADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED): failure when trying to add configuration, such as due to a badly formed configuration.\n - [`ADD_WIFI_RESULT_ALREADY_EXISTS`](/reference/android/provider/Settings#ADD_WIFI_RESULT_ALREADY_EXISTS): the requested configuration already existed so no action was necessary.\n6. If the request is successful, the platform triggers a connection to one of the\n newly saved networks.\n\nCode sample\n\nThe following code sample shows how to save a network or Passpoint\nconfiguration. \n\n class MainActivity : AppCompatActivity() {\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n ...\n }\n\n fun startOperation() {\n val suggestions = ArrayList\u003cWifiNetworkSuggestion\u003e()\n\n // WPA2 configuration\n suggestions.add(\n WifiNetworkSuggestion.Builder()\n .setSsid(\"test111111\")\n .setWpa2Passphrase(\"test123456\")\n .build()\n )\n\n // Open configuration\n suggestions.add(\n WifiNetworkSuggestion.Builder()\n .setSsid(\"test222222\")\n .build()\n )\n\n // Passpoint configuration\n val config = PasspointConfiguration()\n config.credential = Credential().apply {\n realm = \"realm.example.com\"\n simCredential = Credential.SimCredential().apply {\n eapType = 18\n imsi = \"123456*\"\n }\n }\n config.homeSp = HomeSp().apply {\n fqdn = \"test1.example.com\"\n friendlyName = \"Some Friendly Name\"\n }\n suggestions.add(\n WifiNetworkSuggestion.Builder()\n .setPasspointConfig(config)\n .build())\n\n // Create intent\n val bundle = Bundle()\n bundle.putParcelableArrayList(EXTRA_WIFI_NETWORK_LIST, suggestions)\n val intent = Intent(ACTION_WIFI_ADD_NETWORKS)\n intent.putExtras(bundle)\n\n // Launch intent\n startActivityForResult(intent, 0)\n }\n\n override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n super.onActivityResult(requestCode, resultCode, data)\n if(resultCode == RESULT_OK) {\n // user agreed to save configurations: still need to check individual results\n if (data != null && data.hasExtra(EXTRA_WIFI_NETWORK_RESULT_LIST)) {\n for (code in data.getIntegerArrayListExtra(EXTRA_WIFI_NETWORK_RESULT_LIST)) {\n when (code) {\n ADD_WIFI_RESULT_SUCCESS -\u003e\n ... // Configuration saved or modified\n ADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED -\u003e\n ... // Something went wrong - invalid configuration\n ADD_WIFI_RESULT_ALREADY_EXISTS -\u003e\n ... // Configuration existed (as-is) on device, nothing changed\n else -\u003e\n ... // Other errors\n }\n }\n }\n } else {\n // User refused to save configurations\n }\n }\n }"]]