Day93 of #100DaysOfCode

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!

--

--

--

https://www.linkedin.com/in/itskushagra

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Flutter project 1

Hello world Application in Android studio

Learning Android: 0 - The Right Way

How to run Android “App Crawler” testing tool

Kotlin Coroutines — Thread.sleep() vs delay

Khoá học Android Cơ bản

Emulator for Android Studio ?

What’s new in Location on Android 13 Developer Preview 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kushagra Kesav

Kushagra Kesav

https://www.linkedin.com/in/itskushagra

More from Medium

Day61 of #100DaysOfCode

Day52 of #100DaysOfCode

Day76 of #100DaysOfCode

Day83 of #100DaysOfCode