Header
List of the processes running on Android
in: Android  So/Code: Android Data: 15/05/2018
Ora: 15.13:34
Articolo visualizzato: 276 volte

Today I came across the porting of a code to make it compatible for Android 7, so nougat, from the previous version. During this phase I discovered that from the SDK 25 onwards there is no longer the possibility to list via the listFiles of /proc.

This happened for security reasons narrowing the range of action that differentiates Android from iOS. (not of safety is well understood) The code that you glue is the relative one before the SDK 25 version. It remains valid from versions 25 onwards but is restricted to the reading permissions of the user running the application, so it will not list all the processes.

public static List pidof(String str) {
        List < String > listOfPid = new ArrayList();
        for (File file : new File("/proc").listFiles()) {
            if (!file.isFile()) {
                File file2;
                if (Build.VERSION.SDK_INT < 25) {
                    file2 = new File(file.toString() + "/cmdline");;
                }else {
                    file2 = new File(file.toString() + "/comm");
                }
                if (file2.canRead()) {
                    try {
                        BufferedReader bufferedReader = new BufferedReader(new FileReader(file2), 8192);
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else if (readLine.toString().contains(str.toString())) {
                                listOfPid.add(file2.getPath().split("\/")[2].toString());
                            }
                        }
                        bufferedReader.close();
                    } catch (IOException e) {
                    }
                } else {
                    continue;
                }
            }
        }
        return listOfPid;
    }

Alternatively, we always talk about devices with root, you can create a small script in sh:

sudo -c 'pidof processname'

For example, save it in the folder files of our app giving it the correct permissions via adb and then retrieve it via getRuntime().exec().I don't know if there are other valid and functional methods in case you comment to me suggesting?

Thank you all!

This happened for security reasons narrowing the range of action that differentiates Android from iOS. (not of safety is well understood) The code that you glue is the relative one before the SDK 25 versio

Commenti Commenti (0) | User Autore: Guido Camerlingo (Guiz)
Tags: android ps list process /proc comm listare processi background android 7 nougat pidof nome processo pid name





Articoli Correlati
List of the processes running on Android
Rilasciato Iphone OS 4 beta 2 agli sviluppatori
HP Slate 500: Il Tablet con Win7
Come installare Android su pc - Virtual PC
Condivisione File tra Mac e Pc

Commenti

Scrivi Commento
Codice Verifica

Commento massimo 5000 caratteri.(Tutti i campi contrassegnati da * sono obbligatori).

   

Ricerca

Glossario Naviga nel nostro glossario!
Scopri il gergo dei Geek!


 ULTIMI ARTICOLI

114 giorni fa

 [EN] Last Articles

 Siti Amici

Visita il Blog Roll
Contattaci! Diventa nostro amico!



 Hot Downloads

3772

 Categorie

85
163
58
87
13
2
20
36
1
2
5
5
128
7
24
15
62
45

 Code

11
11
3
6
2
24
1
7

 Games

19
45
13

 GUIDE


 Novità Downloads

64
58
3772

 Tags Cloud

gennaio gennaio streaming lego nintendo ossigeno ossigeno xbox streaming http final http wii videogiochi stelle esa xbox scoperte playstation



 CopyRight

Valid XHTML 1.0 Transitional CSS Valido! [Valid RSS] Creative Commons License


Geek-Blog by Flavio Mandato, Giuseppe Vaccaro, Guido Camerlingo, Stefano Natale, Domenico Cavallo is licensed under a Creative Commons Attribuzione-Non opere derivate 2.5 Italia License.
Based on a work at www.geek-blog.it.
Permissions beyond the scope of this license may be available at http://www.geek-blog.it/

Disclaimer - Responsabilità - Pagina generata in 0.109 secondi. Geek-Blog.it