Skip to content
Taku Docs

Version 1.4.0 (current)

Reuse system AI in an Android app

Make one real text request through the source client and per-app user authorization.

Ordinary Android apps can use the device's existing model connection through AiClient, retaining their own package, UID and signing certificate. The client holds no model key and grants no Agent tools, memory access or screenshot capture.

Prepare your project

Use a development device with shared Taku AI and an existing Android Java project. This example targets Java 17, compileSdk / minSdk 36. Work in your own project on the computer; the snippets are not device shell commands.

Requires the system source

AiClient.java comes from the taku-os system source. Clone taku-os first.

Obtain system/ai/client/org/agentos/ai/AiClient.java from the system source and copy it into the matching package directory in your app sources. This is a source client, not a published Maven dependency.

Minimal runnable screen

Merge the permission and Activity declarations into your Manifest; use org.example.takuai for the project namespace and application ID if desired. Save the Java as MainActivity.java. The first background settings read registers the actual Binder caller, initially disabled. “Open Taku AI” opens user authorization; “Generate example” makes one model request.

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="org.agentos.assistant.permission.USE_AI" />
  <queries><provider android:authorities="org.agentos.ai" /></queries>
  <application android:label="Taku AI example">
    <activity android:name="org.example.takuai.MainActivity" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
</manifest>
package org.example.takuai;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.agentos.ai.AiClient;

public final class MainActivity extends Activity {
    private final ExecutorService worker = Executors.newSingleThreadExecutor();
    private AiClient ai;
    private TextView status;
    @Override public void onCreate(Bundle state) {
        super.onCreate(state);
        ai = new AiClient(this);
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        status = new TextView(this);
        Button settings = new Button(this);
        settings.setText("Open Taku AI");
        settings.setOnClickListener(v -> ai.openSettings());
        Button generate = new Button(this);
        generate.setText("Generate example");
        generate.setOnClickListener(v -> worker.execute(() -> {
            try {
                String text = ai.text("Reply with: System AI connected").getString("text");
                show(text);
            } catch (Exception error) { show(error.getMessage()); }
        }));
        layout.addView(settings); layout.addView(generate); layout.addView(status);
        setContentView(layout);
        worker.execute(() -> {
            try { ai.settings(); show("Registered; allow this app in Taku AI."); }
            catch (Exception error) { show(error.getMessage()); }
        });
    }
    private void show(String text) {
        runOnUiThread(() -> { if (!isDestroyed()) status.setText(text); });
    }
    @Override public void onDestroy() { worker.shutdown(); super.onDestroy(); }
}

Install and authorize

Build with your existing Android project tooling, install your APK on a device running Taku OS and open it. Once registration is shown, open Taku AI, enable the master switch and allow this app.

Under Scenes, select Add scene binding, enter org.example.takuai.text (your package name plus .text) and choose a model group. image() uses the <package>.image scene, which needs a group with an image-capable model. While the scene is unbound, calls return an error asking you to bind it. The device UI currently uses Chinese labels:

Scenes = 场景; Add scene binding = 添加场景绑定

Declaring the normal USE_AI permission does not itself authorize model use. Do not change system files or copy the host certificate to bypass user authorization.

Generate and inspect the result

Tap “Generate example” and inspect the actual return. The model is not guaranteed to follow the example prompt verbatim. Taku AI should record your app as the consumer. Disable it and try again to observe rejection.

Blocking client calls belong on a background thread. The example returns only UI updates to the main thread. This makes a real model call and can incur usage.

Images and runtime limits

image(prompt, dataUrl) accepts explicitly provided JPEG / PNG base64 data URLs. It accepts no remote image URL and does not capture a screen for you. Ordinary apps use the model group bound to their own scene. They cannot forge consumer identity or name a model in the request.

The public client currently allows at most two simultaneous public generations and 12 requests per app per minute. Prompts are bounded to 8000 characters, image data URLs to 300000 characters and generation to 1000 tokens. Calls may be rejected by switches, per-app permission, an unbound scene, rate limits, capability or service failures. Display the client error; do not assume automatic retries.

Verification scope

Verified on Pixel 9: a separately signed app completed an actual model call after user authorization, and forged identity and model overrides were rejected. This minimal screen is compile-checked against the client source and has not been run separately on a device. Temporary development deployment does not ensure the runtime survives a device reboot.

Next: for hints and click callbacks, first check the Surfaces matching-certificate requirement. It is a separate authorization path.

Runtime built into the system

Taku OS builds the matching assistant, system task service, Codex and Magpie into read-only system components. Magpie is a third-party open-source model gateway (MIT, by yetone, usemagpie.ai). Taku OS runs it on the phone as part of the system to forward requests to model services. A gateway on the phone does not mean the model runs locally. Existing accounts and Taku AI settings persist across a device reboot.

Research preview · Current availability

Documentation retrieval

Search the published documentation for excerpts and citations. This uses full-text retrieval, not LLM-generated answers.

Every result links to the original article. Read research ideas separately from verified capabilities.

Help and troubleshooting →
Was this article helpful?
Report an issue or give feedback

Delivery to the maintenance queue does not mean it has been handled. Feedback is retained for 90 days.

Built with Fumadocs

On this page