4

I have to make sure to open an app, which is installed on the device by passing the parameters. The application in this case is firefox.

I found something like that but I don't know if it can help me: Link

I found this on Expo but I don't know if it does what I'm looking for: Expo

Some advice?

Paul
  • 3,644
  • 9
  • 47
  • 113

1 Answers1

0

The expo-intent-launcher library has an interface IntentLauncherParams, which must be implemented. To implement the interface you need to create a component in typescript. See: React Native TypeScript and See: Expo Typescript

  1. Create class IntentParams that implements IntentLauncherParams. I did it using constructor to pass some defaults that I needed in my case.

class IntentParams implements IntentLauncherParams {
  type?: string;
  category?: string;
  data?: string;
  flags?: number;
  packageName?: string;
  className?: string;
  extra?: Record<string, any>;
  constructor(flags?: number, extra?: Record<string, any>) {
    this.flags = flags;
    this.extra = extra;
  }
}
  1. Create function Foo() to start activity

const Foo = () => {
    try {
      const transaction = { requestedAmount: amount, currency: currency };
      const transactionJson = JSON.stringify(transaction);

      const extra: Record<string, any> = {
        extra1: "extra1parameter",
        extra2: "extra2parameter",
        extra3: transactionJson,
      };
      const params = new IntentParams(_MY_FLAG_, extra);

      startActivityAsync(_MY_ACTIVITY_, params)
        .then((t) => {
          console.log(t);
          setData(t.data);
        })
        .catch((err) =>
          console.error(
            `Foo inline: ${JSON.stringify(
              err.request
            )}: ${err}`
          )
        );
    } catch (error) {
      console.error(
        `Foo: ${JSON.stringify(
          error.request
        )}: ${error}`
      );
    }
  };
  1. Run function from desired place in your component.
  2. Please remember to import library at the beginning

import { IntentLauncherParams, startActivityAsync } from "expo-intent-launcher";

I hope it will help you.

Nordy
  • 26
  • 2