1import { startActivityAsync, ActivityAction } 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: ActivityAction, intentParams = {}) { 13 return ( 14 <View> 15 <Button 16 onPress={async () => { 17 try { 18 const result = await 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('Location Settings', ActivityAction.LOCATION_SOURCE_SETTINGS)} 43 44 {this.renderSettingsLink('Wireless Settings', ActivityAction.WIRELESS_SETTINGS)} 45 46 {this.renderSettingsLink( 47 'Application Details for Expo Go', 48 ActivityAction.APPLICATION_DETAILS_SETTINGS, 49 { 50 data: 'package:host.exp.exponent', 51 } 52 )} 53 54 {this.renderSettingsLink( 55 'Application Details for Play Store', 56 ActivityAction.APPLICATION_DETAILS_SETTINGS, 57 { 58 data: 'package:com.android.vending', 59 } 60 )} 61 62 {this.renderSettingsLink( 63 'Application Details for not existing package', 64 ActivityAction.APPLICATION_DETAILS_SETTINGS, 65 { 66 data: 'package:package.name.that.doesnt.exist', 67 } 68 )} 69 </ScrollView> 70 ); 71 } 72} 73