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
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
- We will open
manifests/AndroidManifest.xmland add this line just before the
<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.
- Tap the Back button in the device or emulator to close the app.
- 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.
- 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
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!