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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@capacitor/app

v8.0.0

Published

The App API handles high level App state and events.For example, this API emits events when the app enters and leaves the foreground, handles deeplinks, opens other apps, and manages persisted plugin state.

Readme

@capacitor/app

The App API handles high level App state and events. For example, this API emits events when the app enters and leaves the foreground, handles deeplinks, opens other apps, and manages persisted plugin state.

Install

npm install @capacitor/app
npx cap sync

iOS

For being able to open the app from a custom scheme you need to register the scheme first. You can do it by editing the Info.plist file and adding this lines.

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>com.getcapacitor.capacitor</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>mycustomscheme</string>
    </array>
  </dict>
</array>

Android

For being able to open the app from a custom scheme you need to register the scheme first. You can do it by adding this lines inside the activity section of the AndroidManifest.xml.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="@string/custom_url_scheme" />
</intent-filter>

custom_url_scheme value is stored in strings.xml. When the Android platform is added, @capacitor/cli adds the app's package name as default value, but can be replaced by editing the strings.xml file.

Example

import { App } from '@capacitor/app';

App.addListener('appStateChange', ({ isActive }) => {
  console.log('App state changed. Is active?', isActive);
});

App.addListener('appUrlOpen', data => {
  console.log('App opened with URL:', data);
});

App.addListener('appRestoredResult', data => {
  console.log('Restored state:', data);
});

const checkAppLaunchUrl = async () => {
  const { url } = await App.getLaunchUrl();

  console.log('App opened with URL: ' + url);
};

Configuration

| Prop | Type | Description | Default | Since | | ------------------------------ | -------------------- | ------------------------------------------------------------------------------ | ------------------ | ----- | | disableBackButtonHandler | boolean | Disable the plugin's default back button handling. Only available for Android. | false | 7.1.0 |

Examples

In capacitor.config.json:

{
  "plugins": {
    "App": {
      "disableBackButtonHandler": true
    }
  }
}

In capacitor.config.ts:

/// <reference types="@capacitor/app" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    App: {
      disableBackButtonHandler: true,
    },
  },
};

export default config;

API

exitApp()

exitApp() => Promise<void>

Force exit the app. This should only be used in conjunction with the backButton handler for Android to exit the app when navigation is complete.

Ionic handles this itself so you shouldn't need to call this if using Ionic.

Since: 1.0.0


getInfo()

getInfo() => Promise<AppInfo>

Return information about the app.

Returns: Promise<AppInfo>

Since: 1.0.0


getState()

getState() => Promise<AppState>

Gets the current app state.

Returns: Promise<AppState>

Since: 1.0.0


getLaunchUrl()

getLaunchUrl() => Promise<AppLaunchUrl | undefined>

Get the URL the app was launched with, if any.

Returns: Promise<AppLaunchUrl>

Since: 1.0.0


minimizeApp()

minimizeApp() => Promise<void>

Minimizes the application.

Only available for Android.

Since: 1.1.0


toggleBackButtonHandler(...)

toggleBackButtonHandler(options: ToggleBackButtonHandlerOptions) => Promise<void>

Enables or disables the plugin's back button handling during runtime.

Only available for Android.

| Param | Type | | ------------- | ----------------------------------------------------------------------------------------- | | options | ToggleBackButtonHandlerOptions |

Since: 7.1.0


addListener('appStateChange', ...)

addListener(eventName: 'appStateChange', listenerFunc: StateChangeListener) => Promise<PluginListenerHandle>

Listen for changes in the app or the activity states.

On iOS it's fired when the native UIApplication.willResignActiveNotification and UIApplication.didBecomeActiveNotification events get fired. On Android it's fired when the Capacitor's Activity onResume and onStop methods gets called. On Web it's fired when the document's visibilitychange gets fired.

| Param | Type | | ------------------ | ------------------------------------------------------------------- | | eventName | 'appStateChange' | | listenerFunc | StateChangeListener |

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('pause', ...)

addListener(eventName: 'pause', listenerFunc: () => void) => Promise<PluginListenerHandle>

Listen for when the app or the activity are paused.

On iOS it's fired when the native UIApplication.didEnterBackgroundNotification event gets fired. On Android it's fired when the Capacitor's Activity onPause method gets called. On Web it's fired when the document's visibilitychange gets fired and document.hidden is true.

| Param | Type | | ------------------ | -------------------------- | | eventName | 'pause' | | listenerFunc | () => void |

Returns: Promise<PluginListenerHandle>

Since: 4.1.0


addListener('resume', ...)

addListener(eventName: 'resume', listenerFunc: () => void) => Promise<PluginListenerHandle>

Listen for when the app or activity are resumed.

On iOS it's fired when the native UIApplication.willEnterForegroundNotification event gets fired. On Android it's fired when the Capacitor's Activity onResume method gets called, but only after resume has fired first. On Web it's fired when the document's visibilitychange gets fired and document.hidden is false.

| Param | Type | | ------------------ | -------------------------- | | eventName | 'resume' | | listenerFunc | () => void |

Returns: Promise<PluginListenerHandle>

Since: 4.1.0


addListener('appUrlOpen', ...)

addListener(eventName: 'appUrlOpen', listenerFunc: URLOpenListener) => Promise<PluginListenerHandle>

Listen for url open events for the app. This handles both custom URL scheme links as well as URLs your app handles (Universal Links on iOS and App Links on Android)

| Param | Type | | ------------------ | ----------------------------------------------------------- | | eventName | 'appUrlOpen' | | listenerFunc | URLOpenListener |

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('appRestoredResult', ...)

addListener(eventName: 'appRestoredResult', listenerFunc: RestoredListener) => Promise<PluginListenerHandle>

If the app was launched with previously persisted plugin call data, such as on Android when an activity returns to an app that was closed, this call will return any data the app was launched with, converted into the form of a result from a plugin call.

On Android, due to memory constraints on low-end devices, it's possible that, if your app launches a new activity, your app will be terminated by the operating system in order to reduce memory consumption.

For example, that means the Camera API, which launches a new Activity to take a photo, may not be able to return data back to your app.

To avoid this, Capacitor stores all restored activity results on launch. You should add a listener for appRestoredResult in order to handle any plugin call results that were delivered when your app was not running.

Once you have that result (if any), you can update the UI to restore a logical experience for the user, such as navigating or selecting the proper tab.

We recommend every Android app using plugins that rely on external Activities (for example, Camera) to have this event and process handled.

| Param | Type | | ------------------ | ------------------------------------------------------------- | | eventName | 'appRestoredResult' | | listenerFunc | RestoredListener |

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('backButton', ...)

addListener(eventName: 'backButton', listenerFunc: BackButtonListener) => Promise<PluginListenerHandle>

Listen for the hardware back button event (Android only). Listening for this event will disable the default back button behaviour, so you might want to call window.history.back() manually. If you want to close the app, call App.exitApp().

| Param | Type | | ------------------ | ----------------------------------------------------------------- | | eventName | 'backButton' | | listenerFunc | BackButtonListener |

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all native listeners for this plugin

Since: 1.0.0


Interfaces

AppInfo

| Prop | Type | Description | Since | | ------------- | ------------------- | --------------------------------------------------------------------------------------------------- | ----- | | name | string | The name of the app. | 1.0.0 | | id | string | The identifier of the app. On iOS it's the Bundle Identifier. On Android it's the Application ID | 1.0.0 | | build | string | The build version. On iOS it's the CFBundleVersion. On Android it's the versionCode. | 1.0.0 | | version | string | The app version. On iOS it's the CFBundleShortVersionString. On Android it's package's versionName. | 1.0.0 |

AppState

| Prop | Type | Description | Since | | -------------- | -------------------- | --------------------------------- | ----- | | isActive | boolean | Whether the app is active or not. | 1.0.0 |

AppLaunchUrl

| Prop | Type | Description | Since | | --------- | ------------------- | ----------------------------- | ----- | | url | string | The url used to open the app. | 1.0.0 |

ToggleBackButtonHandlerOptions

| Prop | Type | Description | Since | | ------------- | -------------------- | -------------------------------------------------------------------- | ----- | | enabled | boolean | Indicates whether to enable or disable default back button handling. | 7.1.0 |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

URLOpenListenerEvent

| Prop | Type | Description | Since | | -------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | | url | string | The URL the app was opened with. | 1.0.0 | | iosSourceApplication | any | The source application opening the app (iOS only) https://developer.apple.com/documentation/uikit/uiapplicationopenurloptionskey/1623128-sourceapplication | 1.0.0 | | iosOpenInPlace | boolean | Whether the app should open the passed document in-place or must copy it first. https://developer.apple.com/documentation/uikit/uiapplicationopenurloptionskey/1623123-openinplace | 1.0.0 |

RestoredListenerEvent

| Prop | Type | Description | Since | | ---------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | | pluginId | string | The pluginId this result corresponds to. For example, Camera. | 1.0.0 | | methodName | string | The methodName this result corresponds to. For example, getPhoto | 1.0.0 | | data | any | The result data passed from the plugin. This would be the result you'd expect from normally calling the plugin method. For example, CameraPhoto | 1.0.0 | | success | boolean | Boolean indicating if the plugin call succeeded. | 1.0.0 | | error | { message: string; } | If the plugin call didn't succeed, it will contain the error message. | 1.0.0 |

BackButtonListenerEvent

| Prop | Type | Description | Since | | --------------- | -------------------- | --------------------------------------------------------------------------------------------------------- | ----- | | canGoBack | boolean | Indicates whether the browser can go back in history. False when the history stack is on the first entry. | 1.0.0 |

Type Aliases

StateChangeListener

(state: AppState): void

URLOpenListener

(event: URLOpenListenerEvent): void

RestoredListener

(event: RestoredListenerEvent): void

BackButtonListener

(event: BackButtonListenerEvent): void