I Created An Android app using Gemini API

🚀 Speed Up 📱 app development with Gemini API ♊️, Leonardo.ai 🧠, and Android Studio Jelly Fish🦑.

DuAa AwAn
6 min readJan 1, 2024

--

Happy New Year, everyone! 🎊

The Gemini API is now available! 🎉

I’m excited to create a new series using AI and I was fortunate that the Gemini API was just released.

I am making it a multi-part series where I will create a basic Gemini API sample project in the first part. This section of the project will primarily focus on providing a comprehensive introduction to how to set up the sample project.

Furthermore, we will provide a detailed outline of the process for connecting the Gemini API to our project.

The project will also include a simple example of text summarization using the Gemini API based on user input.

By the end of this section, the reader should have a strong foundational knowledge of the sample project creation, text summarization, and the Gemini API setup.

In subsequent parts, we will incorporate a music recommendation system and the major features as follows:

  • Emoji-based playlist creation.
  • Activity-specific playlists: Work out, study, or party with curated playlists for every occasion.
  • Personalized music discovery: Discover amazing new artists and songs that align with your emotions.
  • Playlist sharing and social features: Connect with friends and build a community around music.
  • Beautiful and intuitive interface: Enjoy a sleek, fun, and user-friendly design.

We will be using the following tools:

🛠️ 1. Android Studio JellyFish

♊️ 2. Gemini API

🧠 3. Leonardo.ai

💬 4. Chat GPT

If you haven’t installed Android Studio Jellyfish on your computer or if you have an older version of Android Studio, you can find easy setup instructions in my article below.🖥️👀.

Setup Sample Gemini Project:

From Android Studio, navigate to File > New Project. Choose the Gemini API Starter and click on the next button.

Once the new project dialog box opens, fill in the following:

  1. Type a name for your application project. In our case, we entered the name as “Emoji Tunes.

2. Replace the package name with your application’s package name, for example, we used com.emoji.tunes for this app.

3. Set the save location to the directory where you want to place your project.

Click the next button and it will take you to the next dialog where you need to enter your Gemini API key. If you don’t have one yet you can get one by clicking the Generate API key link at the bottom of the dialog.

It will open Google AI Studio where you can easily generate an API key for a new project.

Copy the generated API key, go back to the new project dialog, paste the key in the API Key text box, and click next.

This will create a sample android Gemini API Summarize Text Project with a MainActivity and SummarizeViewModel containing the Gemini API model.

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
EmojiTunesTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
val generativeModel = GenerativeModel(
modelName = "gemini-pro",
apiKey = BuildConfig.apiKey
)
val viewModel = SummarizeViewModel(generativeModel)
SummarizeRoute(viewModel)
}
}
}
}
}

This sample project created already contains the necessary code to call Gemini API and summarize any text you enter in the TextField and press the go TextButton to continue.

The UI is contained in the Summarize Screen composable at the bottom of the activity as you can see below.

@Composable
fun SummarizeScreen(
uiState: SummarizeUiState = SummarizeUiState.Initial,
onSummarizeClicked: (String) -> Unit = {}
) {
var prompt by remember { mutableStateOf("") }
Column(
modifier = Modifier
.padding(all = 8.dp)
.verticalScroll(rememberScrollState())
) {
Row {
TextField(
value = prompt,
label = { Text(stringResource(R.string.summarize_label)) },
placeholder = { Text(stringResource(R.string.summarize_hint)) },
onValueChange = { prompt = it },
modifier = Modifier
.weight(8f)
)
TextButton(
onClick = {
if (prompt.isNotBlank()) {
onSummarizeClicked(prompt)
}
},

modifier = Modifier
.weight(2f)
.padding(all = 4.dp)
.align(Alignment.CenterVertically)
) {
Text(stringResource(R.string.action_go))
}
}
}
}

Here is the final output of how the text summarization works when the app is run.

That was our final look and basic functionality. Congratulations on learning how to use the sample app without any coding!🎉 Now that you’ve got a basic understanding of the app’s features, you can start exploring its functionality and experiment with different settings.

However, if you want to take your app-building skills to the next level, you’re in for a treat! 🎉👏💻

In Part Two of the series, we will be introducing more advanced features such as:

  • Modifying the Gemini Model to music recommendation system🎶, replacing the summarize text functionality.
  • Learning how to customize the app’s user interface🎨.
  • Adding new functionalities to the app.
  • Emoji-based playlist creation: Express your mood through emojis and get instant music recommendations.
  • Beautiful and intuitive interface: Enjoy a sleek, fun, and user-friendly design.

So buckle up and stay tuned for an exciting journey ahead! 😎👨‍💻📈

🎶 Part Two is Here.

Once you have a solid app setup, you may also be interested in expanding by establishing a web presence. For those interested in creating websites and web apps without coding, here’s a surprise 🎉!

Check out the amazing YCode platform it has plenty of exciting tools to get you started with web development without touching a single line of code all with drag-and-drop visual features.

Give the link below a try and share your thoughts in the comments.

Dear Android Developers, get ready for an amazing year ahead filled with exciting developments and advancements. 🎉

I hope you found this article helpful.

Thank you for following along with this Android article! If you enjoyed learning about Android development, I have some exciting news to share.

I’ve just launched my new YouTube channel, and my first video is all about getting started with iOS and macOS development using the Swift language in Urdu | Hindi.

If you’re curious about broadening your development skills and diving into the Apple ecosystem, this video is the perfect starting point.

👉 Watch the Video Now

By subscribing to my channel, you’ll get access to:

  • Detailed tutorials and guides.
  • Comparisons and best practices between Android and iOS development.
  • Hands-on projects and coding challenges.

Join me on this exciting journey of cross-platform development. Let’s master Swift together and create amazing apps for iOS and macOS!

🔔 Don’t forget to like, share, and subscribe for more awesome content!

Happy Coding! 🧑‍💻💡

--

--

DuAa AwAn

Software Engineer | Android | Tech Writer. Join me in exploring the endless possibilities of app development!