A
A
Alexander2018-09-16 22:24:02
Java
Alexander, 2018-09-16 22:24:02

How to run a system Android application?

This is the python code

import os
os.system("python")

How will the analogue of this code look like in java for Android?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Varakosov, 2018-09-17
@sanya84

There is a huge difference between running applications and shell commands.
For an application, you need to know the package.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage(<пакет>);
if (launchIntent != null) { // null если приложение не найдено или не имеет активити для запуска.
    startActivity(launchIntent);
}

But running something from the shell, without superuser rights, is not easy. The code will be something like this.
try{
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
    outputStream.writeBytes("<команда>\n");
    outputStream.flush();
    outputStream.writeBytes("exit\n");
    outputStream.flush();
    su.waitFor();
}catch(IOException e){
    throw new Exception(e);
}catch(InterruptedException e){
    throw new Exception(e);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question