PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV Mobile 2024 → Intent JAVA vers application Terminal Emulator
Intent JAVA vers application Terminal Emulator
Iniciado por soita, 21,jun. 2017 13:05 - 2 respuestas
Publicado el 21,junio 2017 - 13:05
Bonjour à tous,

Je souhaite pouvoir exécuter une ligne de commande shell directement via un Intent comme le propose le créateur de l'application sur son wiki :

https://github.com/jackpal/Android-Terminal-Emulator/wiki/Launching-Terminal-Emulator-for-Android-from-another-App


Voici ce que je souhaite utiliser selon son exemple :

// opens a new window and runs "echo 'Hi there!'"
// application must declare jackpal.androidterm.permission.RUN_SCRIPT in manifest

Intent i = new Intent("jackpal.androidterm.RUN_SCRIPT");
i.addCategory(Intent.CATEGORY_DEFAULT);
i.putExtra("jackpal.androidterm.iInitialCommand", "echo 'Hi there!'");
startActivity(i);


Gradle me retourne une erreur de type Symbol en me montrant une flèche sous le s de stratActivity(i) ??????????

Pourriez-vous m'éclairer s'il vous plait ?
Publicado el 21,junio 2017 - 14:38
soita a utilisé son clavier pour écrire :
Bonjour à tous,

Je souhaite pouvoir exécuter une ligne de commande shell directement via un
Intent comme le propose le créateur de l'application sur son wiki :

https://github.com/jackpal/Android-Terminal-Emulator/wiki/Launching-Terminal-Emulator-for-Android-from-another-App


Voici ce que je souhaite utiliser selon son exemple :

// opens a new window and runs "echo 'Hi there!'"
// application must declare jackpal.androidterm.permission.RUN_SCRIPT in
manifest

Intent i = new Intent("jackpal.androidterm.RUN_SCRIPT");
i.addCategory(Intent.CATEGORY_DEFAULT);
i.putExtra("jackpal.androidterm.iInitialCommand", "echo 'Hi there!'");
startActivity(i);


Gradle me retourne une erreur de type Symbol en me montrant une flèche sous
le s de stratActivity(i) ??????????

Pourriez-vous m'éclairer s'il vous plait ?


essayez en ajoutant ceci :

Activity act = getActiviteEnCours();
act.startActivity(i);

--
Cordialement JeAn-PhI
Miembro registrado
946 mensajes
Popularité : +102 (110 votes)
Publicado el 21,junio 2017 - 21:02
Bonjour
Cette petite fonction java à mettre en procédure globale de type java devrait répondre à votre besoin
// Exécute une commande avec le shell
// Exemples : 
// ShellExecute("service list")
// ShellExecute("service check phone")
// ShellExecute("ls /system")
// ShellExecute("date")
// ShellExecute("ps")
// ShellExecute("logcat -g")
// ShellExecute("logcat -d")

import java.lang.Runtime;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public static String ShellExecute(String pCommand)
{
StringBuffer output = new StringBuffer();
String response = "";
String line = "";
Process p;

try {
p = Runtime.getRuntime().exec(pCommand);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = reader.readLine())!= null) {
response += line + "\r\n";
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}