necra
necra

Reputation: 1

How to launch android activity in background, or minimized, when screen locked in Android 14 and start the activity with broadcast intent

I'm trying to make an android app to run Python script

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); // Make sure to call super.onCreate() first

        if (!Python.isStarted()) {
            Python.start(new AndroidPlatform(this));
        }

        Python py = Python.getInstance();
        PyObject module = py.getModule("on"); // Assuming "on" is the name of your Python module

        // Call the switch function from your Python module
        PyObject switchFunction = module.callAttr("switch");

    }
}

When this MainActivity launch it shows an empty window (as I dont want a window at all). I want to trigger the MainActivity but only run the script in the background, with no foreground element, and able to call/start this MainActivity when the phone is locked. My best guess is to run this as a Service since the target API is Android 14 but I dont know how.

My ultimate goal is actually to run this python script with a Broadcast Intent (i don't know if this possible please let me know) in Button Mapper app (basically remap my phone physical button to launch this python script)

I'm very new to this so please guide me. Thank you very much.

Upvotes: 0

Views: 94

Answers (0)

Related Questions