Is it possible to receive a notification when an application is launched on an Android device

I want that when I launch any application on the device, it should notify me (programmatically). Is it possible to receive notification of any application at startup (startup).

+5
source share
2 answers

No, this cannot be done using the public SDK.

In the best case scenario, you can constantly poll the ActivityManager for the foreground process that is on top and keep a log of this. However, this is not the most accurate or effective method.

+2
source

ActivityManager # getRunningAppProcesses. , , .

Android , Zygote :

static void Dalvik_dalvik_system_Zygote_forkAndSpecialize(const u4* args,
    JValue* pResult)
{
    pid_t pid;

    pid = forkAndSpecializeCommon(args, false);

    RETURN_INT(pid);
}

libdvm.so.

:

, , , , . , , :

#include <stdio.h>
#include <sys/inotify.h>
#include <assert.h>
int main(int argc, char **argv) {
    char buf[256];
    struct inotify_event *event;
    int fd, wd;
    fd=inotify_init();
    assert(fd > -1);
    assert((wd=inotify_add_watch(fd, "/lib/ld-linux.so.2", IN_OPEN)) > 0);
    printf("Watching for events, wd is %x\n", wd);
    while (read(fd, buf, sizeof(buf))) {
      event = (void *) buf;
      printf("watch %d mask %x name(len %d)=\"%s\"\n",
         event->wd, event->mask, event->len, event->name);
    }
    inotify_rm_watch(fd, wd);
    return 0;
}

root, JNI .

+3

All Articles