Day93 of #100DaysOfCode

Kushagra Kesav
2 min readMay 10, 2022

--

Day93 of #100DaysOfCode

Hii folks 🙌

Today I will be continuing the same pathway in which we will learn to add internet permission.

Unit 4: Internet

Pathway 2: Get and Display Data

https://developer.android.com/courses/android-basics-kotlin/course

Android Permissions

The purpose of permissions on Android is to protect the privacy of an Android user. Android apps must declare or request permissions to access sensitive user data such as contacts, call logs, and certain system features such as camera or internet.

In this step, the app declares the permission(s) it requires by including <uses-permission> tags in the AndroidManifest file.

  • We will open manifests/AndroidManifest.xml and add this line just before the <application> tag:
<uses-permission android:name="android.permission.INTERNET" />
  • Then we will compile and run the app again. If we have a working internet connection, we should see the JSON text containing data related to Mars photos.
  1. Tap the Back button in the device or emulator to close the app.
  2. Put the device or emulator into airplane mode, to simulate a network connection error. Reopen the app from the recents menu, or restart the app from Android Studio.
  3. Click the Logcat tab in Android Studio and note the fatal exception in the log, which looks like this:
3302-3302/com.example.android.marsphotos E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.marsphotos, PID: 3302
java.net.SocketTimeoutException: timeout
...

This error message indicates the application tried to connect and timed out. Exceptions like this are very common in real-time.

That is all for Day93 ✅

Thanks for reading, See you tomorrow!

--

--