Problems about developing a adb extension

Hi everybody,
I want to run adb command to connect another android device via wlan.
I meet some problem while i trying
I has poor knowlege about java so i try chatgpt but codes it gave does not work

import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.runtime.util.YailList;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

@DesignerComponent(version = AdbExtension.VERSION,
    description = "An extension for executing ADB commands without root",
    category = ComponentCategory.EXTENSION,
    nonVisible = true,
    iconName = "images/extension.png")

@SimpleObject(external = true)

public class AdbExtension extends AndroidNonvisibleComponent {
    public static final int VERSION = 1;

    public AdbExtension(ComponentContainer container) {
        super(container.$form());
    }

    @SimpleFunction(description = "Execute ADB command without root")
    public YailList executeAdbCommand(String command) {
        YailList outputList = new YailList();
        try {
            Process process = Runtime.getRuntime().exec("adb " + command);
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                outputList.add(line);
            }
            process.waitFor(); // Wait for the command to finish
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
            outputList.add("Error: " + e.getMessage());
        }
        return outputList;
    }
}

how can i make it
(my english does not well....

That wouldnt work. You can only execute normal Android Shell Commands from Java, that too a limited set of commands unless you have Root Privilege.

Also you cannot directly execute ADB commands from within the app, you need a kind of ADB server to be hosted on to the phone itself to do so.

Some related apps which does this: https://shizuku.rikka.app/

is there any ways to adb other device with root permission?
i read a passage says it can make it via app_process

Im not really sure, there arent simple ways though. You would have to compile the Shizuku source, and build it yourself according to your needs.

But, if you have root permission, you can just execute all of the commands (but not adb)

i want to run shell commands like" settings put global adb_enabled 0".
Is there anyways to access that without root?

this thread might be helpful

Taifun

Not really, Android doesn't allow to it.

I try it before i made this extension.It need run with root permisson,my device do not have it :joy:

I want to run an adb server on my phone so that i can connect to itself by wissnesadb.Then i can run that command

You have to know to compile this then.