javaandroidusageevents

on Android UsageEvents.Event getClass().getName() returns only android.app.usage.UsageEvents$Event and not the name


I'm trying to get the usage on my Android app. Android offers a package to get that info. To get the events, I need to set a time and retrieve a list of events from different apps, I'm only interested on the events from my own app.

UsageStatsManager usm = (UsageStatsManager)context.getSystemService(USAGE_STATS_SERVICE);
Calendar calendar = Calendar.getInstance();
long endTime = calendar.getTimeInMillis();
calendar.add(Calendar.WEEK_OF_YEAR, -1);
long startTime = calendar.getTimeInMillis();
List<UsageStats> luStats = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,startTime,endTime);
while (uEvents.hasNextEvent()){
    UsageEvents.Event e = new UsageEvents.Event();
    uEvents.getNextEvent(e);
    if (e != null){
        Log.d(TAG, "Event: " + e.getPackageName() + "\t" +e.getClass().getName()+ "\t" +  dateFormat.format(new Date (e.getTimeStamp())));
            }
        }

The problem is that the result from e.getClass().getName() is not the name of the class that was used but instead just android.app.usage.UsageEvents$Event . What am I doing wrong? How can I retrieve the name of the class from an event?

Any clue is appreciated!


Solution

  • I found my error.

    The method that I needed was getClassName() instead of getClass().getName(). I changed that on the Event e and I could retrieve all the classes that was looking for.