├── .gitignore
├── android
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ └── strings.xml
│ │ │ └── xml
│ │ │ │ └── provider_paths.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── superhao
│ │ │ └── react_native_apk_manager
│ │ │ ├── ApkManagerPackage.java
│ │ │ └── ApkManagerModule.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── superhao
│ │ │ └── react_native_apk_manager
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── superhao
│ │ └── react_native_apk_manager
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
├── proguard-rules.pro
└── react-native-apk-manager.iml
├── package.json
├── LICENSE
├── index.js
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /android/build
4 | /react-native-mob-sms/*.iml
5 |
6 | # ios
7 | ios/build
--------------------------------------------------------------------------------
/android/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | react-native-apk-manager
3 |
4 |
--------------------------------------------------------------------------------
/android/src/main/res/xml/provider_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
--------------------------------------------------------------------------------
/android/src/test/java/com/superhao/react_native_apk_manager/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.superhao.react_native_apk_manager;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 | defaultConfig {
7 | minSdkVersion 16
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | }
24 |
25 | dependencies {
26 | compile 'com.facebook.react:react-native:+'
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | }
29 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/android/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/android/src/main/java/com/superhao/react_native_apk_manager/ApkManagerPackage.java:
--------------------------------------------------------------------------------
1 | package com.superhao.react_native_apk_manager;
2 |
3 | import com.facebook.react.ReactPackage;
4 | import com.facebook.react.bridge.NativeModule;
5 | import com.facebook.react.bridge.ReactApplicationContext;
6 | import com.facebook.react.uimanager.ViewManager;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Collections;
10 | import java.util.List;
11 |
12 | public class ApkManagerPackage implements ReactPackage {
13 | @Override
14 | public List createNativeModules(ReactApplicationContext reactContext) {
15 | List modules = new ArrayList<>();
16 | modules.add(new ApkManagerModule(reactContext));
17 | return modules;
18 | }
19 |
20 | @Override
21 | public List createViewManagers(ReactApplicationContext reactContext) {
22 | return Collections.emptyList();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/android/src/androidTest/java/com/superhao/react_native_apk_manager/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.superhao.react_native_apk_manager;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.superhao.react_native_apk_manager.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-apk-manager",
3 | "version": "1.1.0",
4 | "description": "React Native bridging library for android to manager apk.(install apk, uninstall apk, open apk, check app is installed or not, check app is installed or not with channel)",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/1556173267/react-native-apk-manager.git"
12 | },
13 | "keywords": [
14 | "react",
15 | "react-native",
16 | "apk-manager",
17 | "android",
18 | "install-apk",
19 | "unstall-apk",
20 | "check-apk-isinstalled",
21 | "open-apk"
22 | ],
23 | "peerDependencies": {
24 | "react-native": ">=0.40"
25 | },
26 | "author": "superhao",
27 | "license": "MIT",
28 | "bugs": {
29 | "url": "https://github.com/1556173267/react-native-apk-manager/issues"
30 | },
31 | "homepage": "https://github.com/1556173267/react-native-apk-manager#readme"
32 | }
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 薛定谔的猫
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import {NativeModules, Platform, PermissionsAndroid } from 'react-native';
4 | const apkManagerModule = NativeModules.ApkManagerModule;
5 |
6 | export function uninstallApk(packageName) {
7 | if (Platform.OS === 'android') {
8 | apkManagerModule.uninstallApk(packageName);
9 | }
10 | }
11 |
12 | export function installApk(filePath) {
13 | if (Platform.OS === 'android') {
14 | PermissionsAndroid.request(
15 | PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE).then((data) => {
16 | if (data === 'granted') {
17 | apkManagerModule.installApk(filePath);
18 | } else {
19 | alert('授权被拒绝');
20 | }
21 | }).catch((err) => {
22 | alert('获取授权失败');
23 | });
24 | }
25 | }
26 |
27 | export function isExpChannel(packageName, metaDataName, channel) {
28 |
29 | if (Platform.OS === 'android') {
30 | return new Promise((resolve, reject) => {
31 | apkManagerModule.isExpChannel(packageName, metaDataName, channel).then((data)=>{
32 | resolve(data);
33 | }).catch((error)=>{
34 | reject(error);
35 | });
36 | });
37 | }
38 |
39 | }
40 |
41 | export function isExpChannels(packageNames, metaDataNames, channels) {
42 |
43 | if (Platform.OS === 'android') {
44 | return new Promise((resolve, reject) => {
45 | apkManagerModule.isExpChannels(packageNames, metaDataNames, channels).then((data)=>{
46 | resolve(data);
47 | }).catch((error)=>{
48 | reject(error);
49 | });
50 | });
51 | }
52 |
53 | }
54 |
55 | export function openApk(packageName) {
56 | if (Platform.OS === 'android') {
57 | apkManagerModule.openApk(packageName);
58 | }
59 | }
60 |
61 | export function isAppInstalled(packageName) {
62 |
63 | if (Platform.OS === 'android') {
64 | return new Promise((resolve, reject) => {
65 | apkManagerModule.isAppInstalled(packageName).then((data)=>{
66 | resolve(data);
67 | }).catch((error)=>{
68 | reject(error);
69 | });
70 | });
71 | }
72 |
73 | }
74 |
75 | export function isAppsInstalled(packageNames) {
76 |
77 | if (Platform.OS === 'android') {
78 | return new Promise((resolve, reject) => {
79 | apkManagerModule.isAppsInstalled(packageNames).then((data)=>{
80 | resolve(data);
81 | }).catch((error)=>{
82 | reject(error);
83 | });
84 | });
85 | }
86 |
87 | }
88 |
89 | export function getAPKInformation(apkFile) {
90 |
91 | if (Platform.OS === 'android') {
92 | return new Promise((resolve, reject) => {
93 | PermissionsAndroid.request(
94 | PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE).then((data) => {
95 | if (data === 'granted') {
96 | apkManagerModule.getAPKInformation(apkFile).then((data)=>{
97 | resolve(data);
98 | }).catch((error)=>{
99 | reject(error);
100 | });
101 | } else {
102 | reject("auth fail");
103 | alert('授权被拒绝');
104 | }
105 | }).catch((err) => {
106 | reject("auth fail");
107 | alert('获取授权失败');
108 | });
109 |
110 | });
111 | }
112 |
113 | }
114 |
115 | export function getAppInformation(packageName) {
116 |
117 | if (Platform.OS === 'android') {
118 | return new Promise((resolve, reject) => {
119 | apkManagerModule.getAppInformation(packageName).then((data)=>{
120 | resolve(data);
121 | }).catch((error)=>{
122 | reject(error);
123 | });
124 | });
125 | }
126 |
127 | }
128 |
129 | export function getAPKMetaDataByKey(apkFile, key) {
130 |
131 | if (Platform.OS === 'android') {
132 | return new Promise((resolve, reject) => {
133 |
134 | PermissionsAndroid.request(
135 | PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE).then((data) => {
136 | if (data === 'granted') {
137 | apkManagerModule.getAPKMetaDataByKey(apkFile, key).then((data)=>{
138 | resolve(data);
139 | }).catch((error)=>{
140 | reject(error);
141 | });
142 | } else {
143 | reject("auth fail");
144 | alert('授权被拒绝');
145 | }
146 | }).catch((err) => {
147 | reject("auth fail");
148 | alert('获取授权失败');
149 | });
150 |
151 | });
152 | }
153 |
154 | }
155 |
156 | export function getAppMetaDataByKey(packageName, key) {
157 |
158 | if (Platform.OS === 'android') {
159 | return new Promise((resolve, reject) => {
160 | apkManagerModule.getAppMetaDataByKey(packageName, key).then((data)=>{
161 | resolve(data);
162 | }).catch((error)=>{
163 | reject(error);
164 | });
165 | });
166 | }
167 |
168 | }
169 |
170 | export function getInstalledAppInfo() {
171 |
172 | if (Platform.OS === 'android') {
173 | return new Promise((resolve, reject) => {
174 | apkManagerModule.getInstalledAppInfo().then((data)=>{
175 | resolve(data);
176 | }).catch((error)=>{
177 | reject(error);
178 | });
179 | });
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-apk-manager
2 | React Native bridging library for android to manager apk.(install apk, uninstall apk, open apk, check app is installed or not, check app is installed or not with channel)
3 |
4 | ## TOC
5 |
6 | * [Installation](#installation)
7 | * [Linking](#linking)
8 | * [Usage](#usage)
9 | * [API](#api)
10 |
11 | ## Installation
12 |
13 | Using npm:
14 |
15 | ```shell
16 | npm install --save react-native-apk-manager
17 | ```
18 |
19 | or using yarn:
20 |
21 | ```shell
22 | yarn add react-native-apk-manager
23 | ```
24 |
25 | ## Linking
26 |
27 | ### Automatic
28 |
29 | ```shell
30 | react-native link react-native-apk-manager
31 | ```
32 |
33 | (or using [`rnpm`](https://github.com/rnpm/rnpm) for versions of React Native < 0.27)
34 |
35 | ```shell
36 | rnpm link react-native-apk-manager
37 | ```
38 |
39 | ### Manual
40 |
41 |
42 | Android
43 |
44 | * **_optional_** in `android/build.gradle`:
45 |
46 | ```gradle
47 | ...
48 | ext {
49 | // dependency versions
50 | compileSdkVersion = "" // default: 27
51 | targetSdkVersion = "" // default: 27
52 | }
53 | ...
54 | ```
55 |
56 | * in `android/app/build.gradle`:
57 |
58 | ```diff
59 | dependencies {
60 | ...
61 | compile "com.facebook.react:react-native:+" // From node_modules
62 | + compile project(':react-native-apk-manager')
63 | }
64 | ```
65 |
66 | * in `android/settings.gradle`:
67 |
68 | ```diff
69 | ...
70 | include ':app'
71 | + include ':react-native-apk-manager'
72 | + project(':react-native-apk-manager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-apk-manager/android')
73 | ```
74 |
75 | #### With React Native 0.29+
76 |
77 | * in `MainApplication.java`:
78 |
79 | ```diff
80 | + import com.superhao.react_native_apk_manager.ApkManagerPackage;
81 |
82 | public class MainApplication extends Application implements ReactApplication {
83 | ......
84 |
85 | @Override
86 | protected List getPackages() {
87 | return Arrays.asList(
88 | + new ApkManagerPackage(),
89 | new MainReactPackage()
90 | );
91 | }
92 |
93 | ......
94 | }
95 | ```
96 |
97 |
98 | ## Usage
99 |
100 | ```js
101 | import * as ApkManager from 'react-native-apk-manager';
102 | ```
103 |
104 | ## API
105 |
106 | | Method | Params | Return Type |
107 | | :----- | :------ | :---------- |
108 | | [isAppInstalled()](#isappinstalledpagenamestring-promiseboolean) | `pageName` | `Promise` |
109 | | [isAppsInstalled()](#isappsinstalledpackagenamesarraystringpromisearrayboolean) | `packageNames>` | `Promise>` |
110 | | [installApk()](#installapkfilepathstring) | `filePath` | `void` |
111 | | [uninstallApk()](#uninstallapkpackagenamestring) | `packageName` | `void` |
112 | | [openApk()](#openapkpackagenamestring) | `packageName` | `void` |
113 | | [isExpChannel()](#isexpchannelpackagenamestring-metadatanamestring-channelstringpromiseboolean) | `packageName, metaDataName, channel` | `Promise` |
114 | | [isExpChannels()](#isexpchannelspackagenamesarraystring-metadatanamesarraystring-channelsarraystringpromisearrayboolean) | `packageNames>, metaDataNames>, channels>` | `Promise>` |
115 | | [getAPKInfomation()](#getapkinformationapkfilestring-promiseobject) | `apkFile` | `Promise