forked from iamvission/react-native-apk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
125 lines (114 loc) · 3.67 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* @providesModule react-native-apk
*/
import { NativeModules } from 'react-native';
var RNAPK = NativeModules.ReactNativeAPK;
var rnApk = {
/**
* Get a list of all the apps that are installed on the device.
*
* @example
* import ReactNativeAPK from "react-native-apk";
* const apps = ReactNativeAPK.getApps();
* console.log(apps); // Array [...]
*
* @return {Array} Returns an array containing the apps.
*/
getApps: function() {
return RNAPK.getApps();
},
/**
* Get a list of the apps the user has installed on the device.
* This method only returns the apps that the user has EXPLICITLY
* installed, ie. via F-Droid/MDroid, Play Store, or by using an APK file.
*
* @example
* import ReactNativeAPK from "react-native-apk";
* const apps = ReactNativeAPK.getNonSystemApps();
* console.log(apps); // Array [...]
*
* @return {Array} Returns an array containing the apps.
*/
getNonSystemApps: function() {
return RNAPK.getNonSystemApps();
},
installedViaAppStore: function() {
return RNAPK.installedViaAppStore();
},
/**
* Install an application to the device.
*
* @example
* import ReactNativeAPK from "react-native-apk";
* ReactNativeAPK.installApp(RNFetchBlob.fs.dirs.DocumentsDir + '/org.mozilla.klar-0.1.0.apk');
*
* @param {String} packagePath - Path to the APK to install.
* @return {void}
*/
installApp: function(packagePath) {
return RNAPK.installApp(packagePath);
},
/**
* Uninstall an application from the device.
* This will send an intent to the system which will show a modal
* asking the user if it is willing to do so.
*
* @example
* import ReactNativeAPK from "react-native-apk";
* const uninstalled = ReactNativeAPK.uninstallApp('org.mozilla.klar');
* console.log(uninstalled); // true
*
* @param {String} packageName - Package's name of the application.
* @return {Boolean} Returns true if the app has been uninstalled.
*/
uninstallApp: function(packageName) {
return RNAPK.uninstallApp(packageName);
},
/**
* A method to check whether an app is installed on the device
* by checking for a package name.
*
* @example
* import ReactNativeAPK from "react-native-apk";
* ReactNativeAPK.installApp(RNFetchBlob.fs.dirs.DocumentsDir + '/org.mozilla.klar-0.1.0.apk');
* let isInstalled = ReactNativeAPK.isAppInstalled();
* console.log(isInstalled); // true
* ReactNativeAPK.uninstallApp('org.mozilla.klar');
* let isInstalled = ReactNativeAPK.isAppInstalled();
* console.log(isInstalled); // false
*
* @param {String} packageName - Package's name of the application.
* @return {Boolean} Returns true if app is installed, false if not.
*/
isAppInstalled: function(packageName) {
return RNAPK.isAppInstalled(packageName);
},
/**
* A method to get an application version based on it's package name.
*
* @example
* import ReactNativeAPK from "react-native-apk";
* const klarVersion = ReactNativeAPK.getAppVersion('org.mozilla.klar');
* console.log(klarVersion); // 0.1.0
*
* @param {String} packageName - Package's name of the application.
* @return {String} Returns the version of the package.
*/
getAppVersion: function(packageName) {
return RNAPK.getAppVersion(packageName);
},
/**
* A method to run an application based on package's name.
*
* @example
* import ReactNativeAPK from "react-native-apk";
* ReactNativeAPK.runApp('org.mozilla.klar');
*
* @param {String} packageName - Package's name of the application.
* @return {void}
*/
runApp: function(packageName) {
return RNAPK.runApp(packageName);
}
};
module.exports = rnApk