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());
    }
    }
    --

ความคิดเห็น • 13

  • @aleyshapapaya
    @aleyshapapaya 2 หลายเดือนก่อน +1

    thank you!!!!!! youve helped me so much

  • @prishanfernando2000
    @prishanfernando2000 3 หลายเดือนก่อน +1

    Thank you 😍

  • @oracleuser-bh1sp
    @oracleuser-bh1sp 7 หลายเดือนก่อน +1

    the clip is clarity screen, cool !

  • @熊先生-u3v
    @熊先生-u3v 4 หลายเดือนก่อน +1

    Thanks a lot!!

  • @AemoDev
    @AemoDev 7 หลายเดือนก่อน +1

    Thank you ❤❤

  • @antoniofuller2331
    @antoniofuller2331 7 หลายเดือนก่อน

    Please refer me to a tutorial about Content Providers with crud sqlite database (java, not kotlin)

    • @ProgrammerWorld
      @ProgrammerWorld  7 หลายเดือนก่อน +1

      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/

    • @antoniofuller2331
      @antoniofuller2331 7 หลายเดือนก่อน

      @@ProgrammerWorld Thank you, but I see nothing about "Content Provider"

  • @LIAMJIEFERM.ORENCIA
    @LIAMJIEFERM.ORENCIA 6 หลายเดือนก่อน

    Can you do with extracting a specific text from an image using gemini?

    • @ProgrammerWorld
      @ProgrammerWorld  6 หลายเดือนก่อน

      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.

    • @LIAMJIEFERM.ORENCIA
      @LIAMJIEFERM.ORENCIA 6 หลายเดือนก่อน

      Cany you make a video without using gemini? Maybe using another api that are open source

    • @ProgrammerWorld
      @ProgrammerWorld  6 หลายเดือนก่อน +1

      @@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/

    • @LIAMJIEFERM.ORENCIA
      @LIAMJIEFERM.ORENCIA 6 หลายเดือนก่อน

      Thanks but i want to do is extracted specific text from a receipt