GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — docs/content/plugins/appavailability.md at docs/linux · NativeScript/docs

Expand file tree

/

appavailability.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
123 lines (91 loc) · 3.83 KB
/

appavailability.md

Copy path

File metadata and controls

123 lines (91 loc) · 3.83 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions
title App Availability
editUrl https://github.com/NativeScript/plugins/tree/main/packages/appavailability/README.md

@nativescript/app-availability

A plugin that checks if an app is installed on a device.

Installation

npm install @nativescript/appavailability

Use @nativescript/app-availability

// examples of what to pass:
// - for iOS: "maps://", "twitter://", "fb://"
// - for Android: "com.facebook.katana"
available('twitter://').then((avail: boolean) => {
  console.log('App available? ' + avail)
})

Open an app (with web fallback)

To open an app installed on the device, call the openUrl() method on the Utils class. Pass the app's identifier URL to the method.

The code below asynchronously checks if the Twitter mobile app is available on the device. If the app is availabe, openUrl() opens it . Otherwise, openUrl() opens the website instead.

import { available } from '@nativescript/appavailability'
import { Utils } from '@nativescript/core'

const twitterScheme = 'twitter://'
available(twitterScheme).then((available) => {
  if (available) {
    // open in the app
    Utils.openUrl(
      twitterScheme +
        (isIOS ? '/user?screen_name=' : 'user?user_id=') +
        'eddyverbruggen',
    )
  } else {
    // open in the default browser
    Utils.openUrl('https://twitter.com/eddyverbruggen')
  }
})

To synchronously check for an app's availability, use the availableSync() function.

import { availableSync } from '@nativescript/appavailability'
import { Utils } from '@nativescript/core'

if (availableSync('twitter://')) {
  Utils.openUrl(
    'twitter://' +
      (isIOS ? '/user?screen_name=' : 'user?user_id=') +
      'eddyverbruggen',
  )
} else {
  Utils.openUrl('https://twitter.com/eddyverbruggen')
}

Determine the correct identifier of an app.

  • Android : search the Play Store and use the id in the URL. For Twitter this is com.twitter.android because the URL is https://play.google.com/store/apps/details?id=com.twitter.android.

  • iOS: Open Safari on your iPhone and type, for example,'twitter://' in the address bar. If the app launches, use that URL as the identifier.

iOS whitelisting

To get useful results on iOS 9+, whitelist the URL Scheme you're querying in the application's Info.plist.

For example, to query for twitter://, whatsapp:// and fb://, edit app/App_ResourcesiOS/Info.plist as follows:

<key>LSApplicationQueriesSchemes</key>
<array>
	<string>fb</string>
	<string>twitter</string>
	<string>whatsapp</string>
</array>

Android Query Permission

Starting from Android API level 30 (Android 11), you must explicitly declare your app's intent to interact with other apps in the Android manifest file AndroidManifest.xml.

<manifest>
    <queries>
        <package android:name="com.whatsapp" />
    </queries>

    <application ...>
    </application>
</manifest>

Replace com.whatsapp with the package name of the app you want to interact with.

API

Methods Return Type Description
available(packageName:string) Promise<boolean> Asynchronously checks if the app with the specified packageName is installed on the device.
availableSync(packageName:string) boolean Synchronously checks if the app with the specified packageName is installed on the device.

License

Apache License Version 2.0

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.