npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rn-app-usage-stats

v2.1.1

Published

app usage stats api for react native

Readme

rn-app-usage-stats

Android app usage statistics API for React Native using TurboModules.

Installation

npm install rn-app-usage-stats

Android Permissions

This library requires Android's Usage Access permission to query app usage statistics.

The permission cannot be requested through the standard Android runtime permission dialog. The library opens the system Usage Access Settings so the user can grant access.

Usage

import {
  requestUsageStatsPermission,
  hasUsageStatsPermission,
  queryAppUsageSessions,
} from 'rn-app-usage-stats';

const granted = await requestUsageStatsPermission();

if (granted) {
  const endTime = Date.now();
  const startTime = endTime - 24 * 60 * 60 * 1000;

  const sessions = await queryAppUsageSessions(startTime, endTime);

  console.log(sessions);
}

Check Permission

You can check whether Usage Access permission has already been granted:

const granted = await hasUsageStatsPermission();

console.log('Usage stats permission:', granted);

Request Permission

If permission has not been granted, call:

const granted = await requestUsageStatsPermission();

This opens the Android Usage Access Settings. The returned promise resolves to true when the user grants permission and false otherwise.

Query App Usage Sessions

const endTime = Date.now();
const startTime = endTime - 24 * 60 * 60 * 1000;

const sessions = await queryAppUsageSessions(startTime, endTime);

The result is grouped by package name:

{
  'com.google.android.youtube': [
    {
      packageName: 'com.google.android.youtube',
      startTime: 1755061200000,
      endTime: 1755061500000,
    },
  ],
  'com.android.chrome': [
    {
      packageName: 'com.android.chrome',
      startTime: 1755061800000,
      endTime: 1755062100000,
    },
  ],
}

Each usage session contains:

export type AppUsageStats = {
  packageName: string;
  startTime: number;
  endTime: number;
};

startTime and endTime are Unix timestamps in milliseconds.

API

hasUsageStatsPermission()

hasUsageStatsPermission(): Promise<boolean>

Returns whether the application currently has Android Usage Access permission.

requestUsageStatsPermission()

requestUsageStatsPermission(): Promise<boolean>

Opens Android Usage Access Settings and resolves with the resulting permission state when the user returns to the application.

queryAppUsageSessions()

queryAppUsageSessions(
  startTime: number,
  endTime: number
): Promise<Record<string, AppUsageStats[]>>

Queries foreground application sessions within the specified time range and groups the results by package name.

queryAppUsageSessionsByPackageName()

queryAppUsageSessionsByPackageName(
  packageName: string,
  startRange: number,
  endRange: number
): Promise<AppUsageStats[]>

Queries real foreground application sessions for an exact Android package name.

queryAggregatedUsageStats()

queryAggregatedUsageStats(
  startRange: number,
  endRange: number
): Promise<AppUsageStatsAggregated[]>

Queries usage statistics aggregated across the specified time range. Android selects the best interval for the range, merges interval buckets, and returns one record per package.

queryAggregatedUsageStatsByPackageName()

queryAggregatedUsageStatsByPackageName(
  packageName: string,
  startRange: number,
  endRange: number
): Promise<AppUsageStatsAggregated[]>

Queries usage statistics aggregated across the specified time range for a specific package.

queryUsageApps()

queryUsageApps(
  startRange: number,
  endRange: number
): Promise<Array<{ appName: string; packageName: string }>>

Returns the display name and package name of apps with foreground usage in the requested range. It does not scan the complete installed-app inventory.

Android Support

This library is currently intended for Android and uses Android's UsageStatsManager APIs.

Usage statistics are subject to Android's Usage Access permission and the behavior of the Android version running on the device.

Contributing

License

MIT


Made with create-react-native-library