Expo module to receive Android intents. Supports only expo Android.
npm install expo-intent-receiver
//app.json
{
"android": {
"intentFilters": [
{
"action": "SEND_MULTIPLE",
"category": [
"DEFAULT"
],
"data": [
{
"mimeType": "image/*"
}
]
},
{
"action": "SEND",
"category": [
"DEFAULT"
],
"data": [
{
"mimeType": "video/*"
}
]
}
]
}
}
import React from 'react';
import { View, Text } from 'react-native';
import * as ExpoIntentReceiver from 'expo-intent-receiver';
export default function App() {
const refIntent = React.useRef(ExpoIntentReceiver.getInitialIntent());
const [data, setData] = React.useState<ExpoIntentReceiver.IntentInfo[]>([]);
React.useEffect(() => {
const subscription = ExpoIntentReceiver.addChangeListener(({ data }) => {
setData((currentData) => [...currentData, ...data])
})
return () => subscription.remove();
}, []);
return (
<View>
<Text>Initial intent: {JSON.stringify(refIntent)}</Text>
{
data.map((d, i) =>
<Text
key={`item-${i}`}>
{i} - {JSON.stringify(d)}
</Text>
)
}
</View>
);
}
Method | Return | Description |
---|---|---|
addIntentListener | IntentReceiverPayload |
Will fire when new filtered intent is received and app is in the background. |
getInitialIntent | IntentInfo[] |
Will return ÌntentInfo[] if filtered intent is available. To be used to capture filtered intent that launched the app. |
clearIntent | void |
Clear intent. |
type IntentInfo = {
contentUri: string;
extension: string;
fileName: string;
mimeType: string;
}
type IntentReceiverPayload = {
data : IntentInfo[];
}
Contributions are very welcome!