PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV Mobile 2024 → Intent JAVA vers application Terminal Emulator
Intent JAVA vers application Terminal Emulator
Started by soita, Jun., 21 2017 1:05 PM - 2 replies
Posted on June, 21 2017 - 1:05 PM
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 ?
Posted on June, 21 2017 - 2:38 PM
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
Registered member
945 messages
Popularité : +102 (110 votes)
Posted on June, 21 2017 - 9:02 PM
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;
}