-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
55 lines (53 loc) · 1.83 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from 'react';
import { Platform, Button, View, StyleSheet, ToastAndroid } from 'react-native';
import Constants from 'expo-constants';
import * as IntentLauncher from 'expo-intent-launcher';
import * as DocumentPicker from 'expo-document-picker';
export default function App() {
const openDocumentPrint = () => {
DocumentPicker.getDocumentAsync({
type: 'application/pdf',
copyToCacheDirectory: false,
})
.then((data) => {
if (data.type === 'success') {
if (Platform.OS === 'android') {
const FLAG_GRANT_READ_URI_PERMISSION = 1;
var res = IntentLauncher.startActivityAsync('android.intent.action.SEND', {
type: 'application/pdf',
flags: FLAG_GRANT_READ_URI_PERMISSION,
extra: {"src":"pkb","dbId":"10101010"},
data: data.uri,
packageName: 'id.astra.zebraprint',
className: 'id.astra.zebraprint.MainActivity',
}).then((res) => {
if(res.resultCode == IntentLauncher.ResultCode.Success){
ToastAndroid.show('Complete', ToastAndroid.SHORT);
}else{
ToastAndroid.show('Cancelled', ToastAndroid.SHORT);
}
}).catch((e) => {
ToastAndroid.show('Application not found!', ToastAndroid.SHORT);
})
}
}
})
.catch((e) => {
console.log(e);
});
};
return (
<View style={styles.container}>
<Button title="Open Document and Print" onPress={openDocumentPrint} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});