How to Use Nearby Wi-Fi Access Permission in Android 13?
Before Android 13 when any android application want to use any wifi related feature within the android application. We have to provide users with fine location permission along with wifi permission to use wifi-related features within the android application. In the new android 13 updates where we can use some of the Wi-Fi-related functionalities without the requirement of any Location permission. In this article, we will be building a simple application in which we will be using nearby Wi-FI access location permission to use Hotspot functionality within our android application.
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.
Step 2: Updating SDK version in build.gradle file.
Navigate to Gradle Scripts>module level build.gradle file and add change compile SDK and target SDK to 33. After that simply sync your project to install it.
Step 3: Working with activity_main.xml.
Navigate to app>res>layout>activity_main.xml and add the below code to it. Comments are added in the code to get to know it in detail.
Step 4: Working with MainActivity.kt file.
Navigate to app>java>your app’s package name>MainActivity.kt file and add the below code to it. Comments are added in the code to get to know it in detail.
Step 5: Adding permissions for using Wifi in the AndroidManifest.xml file.
Navigate to app>AndroidManifest.xml file and add the below permissions to it.
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" android:usesPermissionFlags="neverForLocation" /> <!-- permission for Hotspot --> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Please Login to comment...