This is a News App developed using Kotlin and XML. The app fetches news articles from a news API, displays them in a user-friendly interface, and includes a search functionality to find specific news articles.
- Fetch Latest News: Retrieves news articles from a reliable API.
- Search News: Search for articles by keywords.
- User-Friendly Interface: Designed using XML for a clean and intuitive UI.
- Kotlin-Based: Fully written in Kotlin for robust and modern development.
Before running the app, ensure you have the following:
- Android Studio installed on your system.
- A valid API key from the news API provider.
- Minimum SDK version: 21 (Android 5.0, Lollipop).
- Internet access for fetching news articles.
The app uses a third-party news API to fetch the latest news articles.
-
API Endpoint: Replace
{API_KEY}
with your actual API key.https://newsapi.org/v2/everything?q={query}&apiKey={API_KEY}
-
Required Parameters:
q
: Search keyword (string).apiKey
: Your API key (string).
-
Response: The API returns a JSON response with fields such as
title
,description
,urlToImage
, andpublishedAt
.
Below is the Entity-Relationship (ER) diagram representing the News App:
-
Entities:
- Users: Represents the app users.
- News Articles: Represents the fetched news articles.
- API: Represents the news API used to fetch articles.
-
Relationships:
- Users can search for and read News Articles.
- News Articles are fetched from the API.
[Users] --- Searches ---> [News Articles]
[Users] --- Reads ---> [News Articles]
[API] --- Fetches ---> [News Articles]
- User Interaction: Users interact with the app through a search bar and list of news articles.
- API Request: When a search query is entered, the app sends a request to the News API.
- Data Fetching: The API fetches relevant articles based on the query.
- Display Articles: The fetched news articles are displayed in a recycler view for users to read.
- Continuous Interaction: Users can perform multiple searches and view details of articles.
-
Clone the repository:
git clone https://github.com/your-username/news-app.git
-
Open the project in Android Studio.
-
Add your API key in
Constants.kt
:object Constants { const val BASE_URL = "https://newsapi.org/v2/" const val API_KEY = "your_api_key_here" }
-
Build and run the app on an emulator or physical device.
<EditText
android:id="@+id/searchEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search news..." />
<Button
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search" />
private fun fetchNews(query: String) {
val newsApi = NewsService.create().getNews(query, Constants.API_KEY)
newsApi.enqueue(object : Callback<NewsResponse> {
override fun onResponse(call: Call<NewsResponse>, response: Response<NewsResponse>) {
if (response.isSuccessful) {
val newsList = response.body()?.articles ?: emptyList()
newsRecyclerView.adapter = NewsAdapter(newsList)
}
}
override fun onFailure(call: Call<NewsResponse>, t: Throwable) {
// Handle failure
}
})
}
interface NewsApi {
@GET("everything")
fun getNews(@Query("q") query: String, @Query("apiKey") apiKey: String): Call<NewsResponse>
}
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.