How to set up networks in Android systems and use them?
4 minute(s) read
Published on: Aug 11, 2021
Updated on: Dec 14, 2021
As you know, all mobile devices with all operating systems can connect to networks and do various things through these networks. For example, the Internet can be accessed through a network connection on mobile devices, and users can do whatever they want on the Internet. Of course, it should be noted that the higher the operating system version, the easier it is to connect to networks. It may even launch other applications that require the Internet and network to run through Wi-Fi networks and mobile data.
How to check internet connection on mobile devices
To check your internet connection and see if you are connected to the internet or not, you can use the ConnectivityManager group provided by Android.
1- We call an instance of an object from this group using the getSystemService () method. Like the following:
2- ConnectivityManager check = (ConnectivityManager)
3- this.context.getSystemService (Context.CONNECTIVITY_SERVICE).
4- After you have called an instance of the object or group, you can use the getAllNetworkInfo method. The getAllNetworkInfo method is used to retrieve network information. As below, we can use it to receive all network information.
5- Then, we must check the Connected State. Like the following:
What is NFC?
Note that NFC is an acronym for Near Field Communication. This technology is used to establish communication between two devices wirelessly. The amplitude of this technology is short. The amplitude of this technology is so short that it can establish communication between devices at 4 cm wirelessly.
How does NFC work?
It should be noted that NFC technology, like other technologies such as Bluetooth, Wi-Fi, etc., can be used wirelessly. This technology can send data using radio waves.
How NFC works is based on tags. The data inside the tags can have different modes.
The data transfer rate in NFC is 13.56 MHz, and data can be sent from one device to another at 4 cm at 106, 212, or 424 kbps.
How NFC technology works is as follows:
- Reader / Writer style:
This method permits NFC to read inactive tags.
- P2P style:
The P2P style method allows this to be exchanged for peer data.
- Card emulation style:
This method allows the NFC device to work as the NFC card itself.
How NFC works with Android
To access NFC Hardware, we need to get this permission in Android. Manifest file, such as the following:
It should be noted that not all devices with Android system have NFC capability and cannot support it, so we need to apply settings to make sure google play is a device that has NFC Hardware and supports it. Therefore, we act as follows:
The Android.nfc package is provided by Android for connecting to other devices, which includes the following:
it represents an immutable NDEF Message
This group can be used to display the immutable NDEF recording.
This group is used to display the local NFC adapter.
This group includes all information about NFC events.
This group can be used to provide an instance of NfcAdapter.
- Tag: Displays the NFC tag.
Some of the filters that the NFC tag system works with are as follows:
This intent is used to start an activity when a tag has an NDEF payload.
This intent starts an activity when a tag does not have NDEF.
This intent can also be used with no ACTION_NDEF_DISCOVERED and ACTION_TECH_DISCOVERED hintent activities.
WiFi network in Android
It should be noted that Android systems have provided the WifiManager API to organize the Wi-Fi connection. We can call this group provided by the Android system using the getSystemService method. Like the following:
To have a list of wireless networks, you must register BroadcastReceiver, which you can also use registerReceiver to register. Like the following:
Wi-Fi can be called from the WifiManager group using the start scan method. Like the following:
Here is an example to better understand the Wi-Fi stream in Android systems.
In this example, we create an application that scans the list of wireless networks and shows us the result.
1- I use Eclipse IDE to create an Android application.
2- Name it WIFI in the package com.example.wifi.
3- Modify the src / MainActivity.java file to add a different code.
4- The res/layout / activity_main file must be modified to add the XML component.
5- Change AndroidManifest.xml to get permissions.
6- All contents and codes that are completely included in the file and program are as follows:
7- The codes in the res/layout / activity_main.xml file after the change are as follows:
8- The content of the AndroidManifest.xml file is also listed below:
About our Android and iOS app development services