├── .gitattributes
├── android
├── .settings
│ └── org.eclipse.buildship.core.prefs
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ ├── androidinstalledapps
│ │ ├── RNAndroidInstalledAppsPackage.java
│ │ └── RNAndroidInstalledAppsModule.java
│ │ └── helper
│ │ └── Utility.java
├── .classpath
├── build.gradle
└── .project
├── index.js
├── .gitignore
├── package.json
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
--------------------------------------------------------------------------------
/android/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.project.dir=../../../android
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/android/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | apply plugin: 'com.android.library'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.1"
7 |
8 | defaultConfig {
9 | minSdkVersion 16
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | ndk {
14 | abiFilters "armeabi-v7a", "x86"
15 | }
16 | }
17 | lintOptions {
18 | warning 'InvalidPackage'
19 | }
20 | }
21 |
22 | dependencies {
23 | compile 'com.facebook.react:react-native:0.20.+'
24 | }
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | // let RNAndroidInstalledApps = require("react-native").NativeModules
2 | // .RNAndroidInstalledApps;
3 |
4 | import { NativeModules } from "react-native";
5 |
6 | const { RNAndroidInstalledApps } = NativeModules;
7 |
8 | module.exports = {
9 | getApps(): Promise {
10 | return RNAndroidInstalledApps.getApps();
11 | },
12 | getNonSystemApps(): Promise {
13 | return RNAndroidInstalledApps.getNonSystemApps();
14 | },
15 | getSystemApps(): Promise {
16 | return RNAndroidInstalledApps.getSystemApps();
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # OSX
3 | #
4 | .DS_Store
5 |
6 | # node.js
7 | #
8 | node_modules/
9 | npm-debug.log
10 | yarn-error.log
11 |
12 |
13 | # Xcode
14 | #
15 | build/
16 | *.pbxuser
17 | !default.pbxuser
18 | *.mode1v3
19 | !default.mode1v3
20 | *.mode2v3
21 | !default.mode2v3
22 | *.perspectivev3
23 | !default.perspectivev3
24 | xcuserdata
25 | *.xccheckout
26 | *.moved-aside
27 | DerivedData
28 | *.hmap
29 | *.ipa
30 | *.xcuserstate
31 | project.xcworkspace
32 |
33 |
34 | # Android/IntelliJ
35 | #
36 | build/
37 | .idea
38 | .gradle
39 | local.properties
40 | *.iml
41 |
42 | # BUCK
43 | buck-out/
44 | \.buckd/
45 | *.keystore
46 |
--------------------------------------------------------------------------------
/android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | react-native-android-installed-apps
4 | Project react-native-android-installed-apps created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-android-installed-apps",
3 | "version": "1.0.0",
4 | "description": "API to retrieve installed apps information using native built-ins",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [
10 | "react-native",
11 | "android",
12 | "installed",
13 | "apps",
14 | "packeges",
15 | "applications"
16 | ],
17 | "author": {
18 | "name": "Ayman Alaiwah",
19 | "email": "aymanalaiwah.dev@gmail.com",
20 | "url": "https://github.com/progaymanalaiwah/react-native-android-installed-apps"
21 | },
22 | "license": "MIT",
23 | "peerDependencies": {
24 | "react-native": "^0.41.2",
25 | "react-native-windows": "0.41.0-rc.1"
26 | },
27 | "repository": {
28 | "type": "git",
29 | "url": "git+https://github.com/progaymanalaiwah/react-native-android-installed-apps.git"
30 | },
31 | "bugs": {
32 | "url": "https://github.com/progaymanalaiwah/react-native-android-installed-apps/issues"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/android/src/main/java/com/androidinstalledapps/RNAndroidInstalledAppsPackage.java:
--------------------------------------------------------------------------------
1 |
2 | package com.androidinstalledapps;
3 |
4 | import java.util.Arrays;
5 | import java.util.Collections;
6 | import java.util.List;
7 |
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.react.bridge.NativeModule;
10 | import com.facebook.react.bridge.ReactApplicationContext;
11 | import com.facebook.react.uimanager.ViewManager;
12 | import com.facebook.react.bridge.JavaScriptModule;
13 | public class RNAndroidInstalledAppsPackage implements ReactPackage {
14 | @Override
15 | public List createNativeModules(ReactApplicationContext reactContext) {
16 | return Arrays.asList(new RNAndroidInstalledAppsModule(reactContext));
17 | }
18 |
19 | // Deprecated from RN 0.47
20 | public List> createJSModules() {
21 | return Collections.emptyList();
22 | }
23 |
24 | @Override
25 | public List createViewManagers(ReactApplicationContext reactContext) {
26 | return Collections.emptyList();
27 | }
28 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # react-native-android-installed-apps
3 |
4 | ## Getting started
5 |
6 | `$ npm install react-native-android-installed-apps --save`
7 |
8 | ### Mostly automatic installation
9 |
10 | `$ react-native link react-native-android-installed-apps`
11 |
12 | ### Manual installation
13 |
14 |
15 |
16 | #### Android
17 |
18 | 1. Open up `android/app/src/main/java/[...]/MainActivity.java`
19 | - Add `import com.androidinstalledapps.RNAndroidInstalledAppsPackage;` to the imports at the top of the file
20 | - Add `new RNAndroidInstalledAppsPackage()` to the list returned by the `getPackages()` method
21 | 2. Append the following lines to `android/settings.gradle`:
22 | ```
23 | include ':react-native-android-installed-apps'
24 | project(':react-native-android-installed-apps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-installed-apps/android')
25 | ```
26 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
27 | ```
28 | compile project(':react-native-android-installed-apps')
29 | ```
30 |
31 |
32 | ## Methods
33 |
34 | #### 1 - getApps()
35 | #### 2 - getNonSystemApps()
36 | #### 3 - getSystemApps()
37 |
38 | ## Return Result
39 |
40 | - packageName
41 | - versionName
42 | - versionCode
43 | - firstInstallTime
44 | - lastUpdateTime
45 | - appName
46 | - icon // Base64
47 | - apkDir
48 | - size // Bytes
49 |
50 |
51 | ## Usage
52 | ```javascript
53 | import RNAndroidInstalledApps from 'react-native-android-installed-apps';
54 |
55 |
56 | RNAndroidInstalledApps.getApps()
57 | .then(apps => {
58 | this.setState({apps})
59 | })
60 | .catch(error => {
61 | alert(error);
62 | });
63 |
64 | ```
65 |
--------------------------------------------------------------------------------
/android/src/main/java/com/helper/Utility.java:
--------------------------------------------------------------------------------
1 | package com.helper;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.Canvas;
6 | import android.graphics.drawable.BitmapDrawable;
7 | import android.graphics.drawable.Drawable;
8 | import android.util.Base64;
9 |
10 | import java.io.ByteArrayOutputStream;
11 |
12 | public class Utility {
13 |
14 | public static String convert(Drawable drawable) {
15 | try {
16 | return convert(drawableToBitmap(drawable));
17 | } catch (Exception e) {
18 | e.printStackTrace();
19 | }
20 | return "";
21 | }
22 |
23 | public static String convert(Bitmap bitmap) {
24 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
25 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
26 |
27 | return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT);
28 | }
29 |
30 | public static Bitmap drawableToBitmap(Drawable drawable) {
31 | Bitmap bitmap = null;
32 |
33 | if (drawable instanceof BitmapDrawable) {
34 | BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
35 | if (bitmapDrawable.getBitmap() != null) {
36 | return bitmapDrawable.getBitmap();
37 | }
38 | }
39 |
40 | if (drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) {
41 | bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1
42 | // pixel
43 | } else {
44 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
45 | Bitmap.Config.ARGB_8888);
46 | }
47 |
48 | Canvas canvas = new Canvas(bitmap);
49 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
50 | drawable.draw(canvas);
51 | return bitmap;
52 | }
53 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/androidinstalledapps/RNAndroidInstalledAppsModule.java:
--------------------------------------------------------------------------------
1 |
2 | package com.androidinstalledapps;
3 |
4 | import com.facebook.react.bridge.ReactApplicationContext;
5 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
6 | import com.facebook.react.bridge.ReactMethod;
7 | import com.facebook.react.bridge.Callback;
8 | import com.facebook.react.bridge.Promise;
9 | import com.facebook.react.bridge.WritableMap;
10 | import com.facebook.react.bridge.WritableArray;
11 | import com.facebook.react.bridge.Arguments;
12 |
13 | import android.content.pm.PackageInfo;
14 | import android.content.pm.ApplicationInfo;
15 | import android.content.pm.PackageManager;
16 | import android.graphics.drawable.Drawable;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Map;
21 | import java.util.HashMap;
22 | import java.io.File;
23 |
24 | import javax.annotation.Nullable;
25 |
26 | import com.helper.*;
27 |
28 | public class RNAndroidInstalledAppsModule extends ReactContextBaseJavaModule {
29 |
30 | private final ReactApplicationContext reactContext;
31 |
32 | public RNAndroidInstalledAppsModule(ReactApplicationContext reactContext) {
33 | super(reactContext);
34 | this.reactContext = reactContext;
35 | }
36 |
37 | @Override
38 | public String getName() {
39 | return "RNAndroidInstalledApps";
40 | }
41 |
42 | @ReactMethod
43 | public void getApps(Promise promise) {
44 | try {
45 | PackageManager pm = this.reactContext.getPackageManager();
46 | List pList = pm.getInstalledPackages(0);
47 | WritableArray list = Arguments.createArray();
48 | for (int i = 0; i < pList.size(); i++) {
49 | PackageInfo packageInfo = pList.get(i);
50 | WritableMap appInfo = Arguments.createMap();
51 |
52 | appInfo.putString("packageName", packageInfo.packageName);
53 | appInfo.putString("versionName", packageInfo.versionName);
54 | appInfo.putDouble("versionCode", packageInfo.versionCode);
55 | appInfo.putDouble("firstInstallTime", (packageInfo.firstInstallTime));
56 | appInfo.putDouble("lastUpdateTime", (packageInfo.lastUpdateTime));
57 | appInfo.putString("appName", ((String) packageInfo.applicationInfo.loadLabel(pm)).trim());
58 |
59 | Drawable icon = pm.getApplicationIcon(packageInfo.applicationInfo);
60 | appInfo.putString("icon", Utility.convert(icon));
61 |
62 | String apkDir = packageInfo.applicationInfo.publicSourceDir;
63 | appInfo.putString("apkDir", apkDir);
64 |
65 | File file = new File(apkDir);
66 | double size = file.length();
67 | appInfo.putDouble("size", size);
68 |
69 | list.pushMap(appInfo);
70 | }
71 | promise.resolve(list);
72 | } catch (Exception ex) {
73 | promise.reject(ex);
74 | }
75 | }
76 |
77 | @ReactMethod
78 | public void getNonSystemApps(Promise promise) {
79 | try {
80 | PackageManager pm = this.reactContext.getPackageManager();
81 | List pList = pm.getInstalledPackages(0);
82 | WritableArray list = Arguments.createArray();
83 | for (int i = 0; i < pList.size(); i++) {
84 | PackageInfo packageInfo = pList.get(i);
85 | WritableMap appInfo = Arguments.createMap();
86 |
87 | if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
88 | appInfo.putString("packageName", packageInfo.packageName);
89 | appInfo.putString("versionName", packageInfo.versionName);
90 | appInfo.putDouble("versionCode", packageInfo.versionCode);
91 | appInfo.putDouble("firstInstallTime", (packageInfo.firstInstallTime));
92 | appInfo.putDouble("lastUpdateTime", (packageInfo.lastUpdateTime));
93 | appInfo.putString("appName", ((String) packageInfo.applicationInfo.loadLabel(pm)).trim());
94 |
95 | Drawable icon = pm.getApplicationIcon(packageInfo.applicationInfo);
96 | appInfo.putString("icon", Utility.convert(icon));
97 |
98 | String apkDir = packageInfo.applicationInfo.publicSourceDir;
99 | appInfo.putString("apkDir", apkDir);
100 |
101 | File file = new File(apkDir);
102 | double size = file.length();
103 | appInfo.putDouble("size", size);
104 |
105 | list.pushMap(appInfo);
106 | }
107 | }
108 | promise.resolve(list);
109 | } catch (Exception ex) {
110 | promise.reject(ex);
111 | }
112 |
113 | }
114 |
115 | @ReactMethod
116 | public void getSystemApps(Promise promise) {
117 | try {
118 | PackageManager pm = this.reactContext.getPackageManager();
119 | List pList = pm.getInstalledPackages(0);
120 | WritableArray list = Arguments.createArray();
121 | for (int i = 0; i < pList.size(); i++) {
122 | PackageInfo packageInfo = pList.get(i);
123 | WritableMap appInfo = Arguments.createMap();
124 |
125 | if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
126 | appInfo.putString("packageName", packageInfo.packageName);
127 | appInfo.putString("versionName", packageInfo.versionName);
128 | appInfo.putDouble("versionCode", packageInfo.versionCode);
129 | appInfo.putDouble("firstInstallTime", (packageInfo.firstInstallTime));
130 | appInfo.putDouble("lastUpdateTime", (packageInfo.lastUpdateTime));
131 | appInfo.putString("appName", ((String) packageInfo.applicationInfo.loadLabel(pm)).trim());
132 |
133 | Drawable icon = pm.getApplicationIcon(packageInfo.applicationInfo);
134 | appInfo.putString("icon", Utility.convert(icon));
135 |
136 | String apkDir = packageInfo.applicationInfo.publicSourceDir;
137 | appInfo.putString("apkDir", apkDir);
138 |
139 | File file = new File(apkDir);
140 | double size = file.length();
141 | appInfo.putDouble("size", size);
142 |
143 | list.pushMap(appInfo);
144 | }
145 | }
146 | promise.resolve(list);
147 | } catch (Exception ex) {
148 | promise.reject(ex);
149 | }
150 |
151 | }
152 | }
--------------------------------------------------------------------------------