invertase / react-native-notifee

Moved to https://github.com/invertase/notifee
https://invertase.io/blog/open-sourcing-notifee
Other
465 stars 31 forks source link

How to add press action on notification to open the file. #308

Closed shubhamdeol closed 3 years ago

shubhamdeol commented 3 years ago

I want to show local notification on successful file download.

Here is how I am trying

const contentUri = await FileSystem.getContentUriAsync(filePath);

const notificationId = await notifee.displayNotification({
    title: 'Excel Report',
    body: 'File Successfully downloaded',
    android: {
      channelId: NotificationChannelNames.DownloadProgress,
      pressAction: {
        id: 'default',
        launchActivity: contentUri,
      },
    },
  });

What is correct way to pass an intent which opens file in mobile.

shubhamdeol commented 3 years ago

One way can be to send pressAction id as

 pressAction: {
        id: 'download',
      },

and inside app listeners.

In press event handle it like

if (detail.notification?.android?.pressAction?.id === 'download') {
  FileSystem.getContentUriAsync(uri).then((cUri) => {
    IntentLauncher.startActivityAsync('android.intent.action.VIEW', {
      data: cUri,
      flags: 1,
    });
  });
}

This required me to save fileUri in AsyncStorage and clear async on press action action. More better way could be if I could pass the intent from the place I am creating the notificaiton.

helenaford commented 3 years ago

Hey, this is an interesting use case! At the moment we only support launching a react activity. I'm not sure if it's possible but it could be something we look into.

helenaford commented 3 years ago

Closing as it's not something on the roadmap as there's no clear solution right now.