react-native-android-intent-launcher

0.3.0 • Public • Published

react-native-anroid-intent-launcher

version downloads downloads

call native function startActivity in react-native

isPackageInstalled and isAppInstalled method is to check to see if the app is installed openApp and startAppByPackageName method will run the app when it is installed.

Why Fork

Original Repository is react-native-intent-launcher

Fixes the following issues when building React Native 0.60 or later.

And

Added isPackageInstalled, openApp method

Use isPackageInstalled method when isAppInstalled method doesn't work.

Use openApp method when startAppByPackageName method doesn't work.

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Description

You can call native function startActivity in react-native to do something with Intent which can only be solved with android native code

Installation

Using yarn (RN 0.60 and and above)

yarn add react-native-android-intent-launcher

Using yarn (RN 0.59 and and below)

yarn add react-native-android-intent-launcher
react-native link react-native-android-intent-launcher

Usage

import { Linking } from 'react-native'
import IntentLauncher, { IntentConstant } from 'react-native-intent-launcher'
 
...
 
IntentLauncher.startActivity({
    action: 'android.settings.APPLICATION_DETAILS_SETTINGS',
    data: 'package:com.example'
})
 
// check if app is installed by package name
IntentLauncher.isAppInstalled('com.your.app')
  .then((result) => {
    console.log('isAppInstalled yes');
  })
  .catch((error) => console.warn('isAppInstalled: no', error));
 
// open another app by package name
IntentLauncher.startAppByPackageName('com.your.app')
  .then((result) => {
    console.log('startAppByPackageName started');
  })
  .catch((error) => console.warn('startAppByPackageName: could not open', error));
 
const downloadURL = "https://www.your.com/download"
 
IntentLauncher.isPackageInstalled('com.your.app')
  .then(isInstalled => {
    if (isInstalled) 
      IntentLauncher.openApp(appInfo.package, options)
    else if (downloadURL) 
      Linking.openURL(downloadURL)
        .catch(err => console.error("An error occurred", err))
    else
      console.log("There is no path to download the app")
  })
 
...

Properties

  • action String
  • data String
  • category String
  • flags String
  • extra Object
  • packageName String
  • className String
  • flags Number

In the IntentConstant, we provide some constants for these properties, you can look up document provided by google to find out property we didn't support currently.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.0
    271
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.3.0
    271

Package Sidebar

Install

npm i react-native-android-intent-launcher

Weekly Downloads

206

Version

0.3.0

License

MIT

Unpacked Size

367 kB

Total Files

9

Last publish

Collaborators

  • genii-services