How to integrate google's Gemini AI in Android App Java code?
ฝัง
- เผยแพร่เมื่อ 2 ต.ค. 2024
- This video shows the steps to integrate the Gemini's API, Google's AI tool, in your Android App's Java code.
It refers below document for quickstarter guide:
ai.google.dev/...
For APIKey generation, one can use below link:
aistudio.googl...
I hope you like this video. For any questions, suggestions or appreciation please contact us at: programmerworl... or email at: programmerworld1990@gmail.com
Complete source code and other details/ steps of this video are posted in the below link:
programmerworl...
However, the main Java code is copied below also for reference:
package com.programmerworld.geminijavaapiandroidapp;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.google.ai.client.generativeai.GenerativeModel;
import com.google.ai.client.generativeai.java.GenerativeModelFutures;
import com.google.ai.client.generativeai.type.Content;
import com.google.ai.client.generativeai.type.GenerateContentResponse;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
public class MainActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
}
public void buttonCallGeminiAPI(View view){
// For text-only input, use the gemini-pro model
GenerativeModel gm = new GenerativeModel(/* modelName */ "gemini-pro",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
/* apiKey */ "AIzaSyBl4A8CG78TFmXjG1zyJgQaSGSmNes4JI");
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
Content content = new Content.Builder()
.addText("Write a story about a magic backpack.")
.build();
ListenableFuture-GenerateContentResponse- response = model.generateContent(content);
Futures.addCallback(response, new FutureCallback-GenerateContentResponse-() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
textView.setText(resultText);
}
@Override
public void onFailure(Throwable t) {
textView.setText(t.toString());
}
}, this.getMainExecutor());
}
}
--
thank you!!!!!! youve helped me so much
Thank you 😍
the clip is clarity screen, cool !
Thanks a lot!!
Thank you ❤❤
Please refer me to a tutorial about Content Providers with crud sqlite database (java, not kotlin)
Below may help:
programmerworld.co/android/how-to-create-a-custom-calendar-app-to-store-reminders-and-events-using-sqlite-database-in-android-studio/
programmerworld.co/android/how-to-fetch-data-from-sqlite-database-and-put-that-in-a-pdf-file-in-your-android-app-source-code/
programmerworld.co/android/how-to-store-images-in-sqlite-database-insert-update-delete-and-fetch-in-your-android-app/
@@ProgrammerWorld Thank you, but I see nothing about "Content Provider"
Can you do with extracting a specific text from an image using gemini?
As of now Gemini is not processing images as Google is revamping the image part. Once it is released, would make another tutorial to demonstrate the text recognition functionality.
Cany you make a video without using gemini? Maybe using another api that are open source
@@LIAMJIEFERM.ORENCIA You can refer my below pages:
programmerworld.co/android/how-to-read-texts-from-an-image-ocr-using-google-vision-library-in-your-android-app/
programmerworld.co/android/how-to-create-your-optical-character-recognition-ocr-android-app-and-convert-the-text-into-speech/
Thanks but i want to do is extracted specific text from a receipt