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