How to delegate a download request to another app with React Native

Viewed 63

I'm developing a simple app with expo and react native that has a simple button. When I click on the button it sends a request to a web service that simply returns a downloadable url for a file. fore example "https://somesite.com/video.mp4"

I am using fetch api to send the request to the server. Here is my code:

import { StatusBar } from "expo-status-bar";
import React from "react";
import { Button, StyleSheet, Text, View } from "react-native";

const handlePress = () => {
  fetch("https://myserver.dev/api")
    .then((response) => response.json())
    .then((responseJson) => alert(responseJson))
    .catch((error) => alert(error));
};

export default function App() {
  return (
    <View style={styles.container}>
      <Button title="Get Download Link" onPress={handlePress} />
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

When I run the code It successfully alerts me the download url. But instead of showing this alert I want to delegate the actual download process to another app in the system. There is a concept in the android programming world named Implicit Intents. It lets developers to delegate a task to another app installed on the system. But it is the Android OS that lets the user choose the appropriate app for doing this task. How can I do this in Expo and React Native. Now this is exactly what I want to do: After getting download url, The system must show the user a list of apps that appropriate for download from a URL (eg. ADM or Chrome). And then I pass the file url I got from the server to that app to process the actual download task.

0 Answers
Related