1import * as IntentLauncher from 'expo-intent-launcher';
2import React from 'react';
3import { Platform, ScrollView, Text, ToastAndroid, View } from 'react-native';
4
5import Button from '../components/Button';
6
7export default class IntentLauncherScreen extends React.Component {
8  static navigationOptions = {
9    title: 'IntentLauncher',
10  };
11
12  renderSettingsLink(title: string, activityAction: string, intentParams = {}) {
13    return (
14      <View>
15        <Button
16          onPress={async () => {
17            try {
18              const result = await IntentLauncher.startActivityAsync(activityAction, intentParams);
19              ToastAndroid.show(`Activity finished: ${JSON.stringify(result)}`, ToastAndroid.SHORT);
20            } catch (e) {
21              ToastAndroid.show(`An error occurred: ${e.message}`, ToastAndroid.SHORT);
22            }
23          }}
24          title={title}
25          style={{ marginBottom: 10 }}
26        />
27      </View>
28    );
29  }
30
31  render() {
32    if (Platform.OS !== 'android') {
33      return (
34        <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
35          <Text>IntentLauncherAndroid is only available on Android.</Text>
36        </View>
37      );
38    }
39
40    return (
41      <ScrollView style={{ padding: 10 }}>
42        {this.renderSettingsLink(
43          'Location Settings',
44          IntentLauncher.ACTION_LOCATION_SOURCE_SETTINGS
45        )}
46
47        {this.renderSettingsLink('Wireless Settings', IntentLauncher.ACTION_WIRELESS_SETTINGS)}
48
49        {this.renderSettingsLink(
50          'Application Details for Expo Go',
51          IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
52          {
53            data: 'package:host.exp.exponent',
54          }
55        )}
56
57        {this.renderSettingsLink(
58          'Application Details for Play Store',
59          IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
60          {
61            data: 'package:com.android.vending',
62          }
63        )}
64
65        {this.renderSettingsLink(
66          'Application Details for not existing package',
67          IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
68          {
69            data: 'package:package.name.that.doesnt.exist',
70          }
71        )}
72      </ScrollView>
73    );
74  }
75}
76