Oasis Feng
Oasis Feng

Reputation: 7510

EventLog.readEvents() not working

I use following code in Android app to read event logs

    final Collection<Event> events = new ArrayList<Event>();
    try {
        final int tag = EventLog.getTagCode("am_proc_start");
        EventLog.readEvents(new int[] { tag }, events);
        System.out.println(events);
    } catch (final IOException e) {
        e.printStackTrace();
    }

But what I got is an empty events list. Still I can get all these events by running command adb logcat events -v.

Upvotes: 1

Views: 1193

Answers (1)

Oasis Feng
Oasis Feng

Reputation: 7510

First add android.permission.READ_LOGS permission, then on Android 4.1+, use this shell command to actually grant permission:

adb shell pm grant your.app.package android.permission.READ_LOGS

Now I can successfully read all logs.

Upvotes: 2

Related Questions