From 9218baf96fa8b1a14dbf9753f3c869335debceb4 Mon Sep 17 00:00:00 2001 From: matheus-bg Date: Fri, 13 Nov 2020 22:54:05 -0300 Subject: [PATCH 1/2] Small change to ensure that the foreground service will be killed. I noticed that my application was killed because the foreground service continued to run after closing the app. So, I made this change to solve this problem by adding the stopWithTask tag on the AndroidManifest.xml and calling stopSelf inside onTaskRemoved. --- README.md | 20 +++++++------ android/.project | 28 +++++++++++++++++++ .../VIForegroundService.java | 7 +++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 android/.project diff --git a/README.md b/README.md index 5898411..c2b5ac4 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,9 @@ See [the Android official documentation](https://developer.android.com/guide/com ``` 2. Add VIForegroundService as a service to the application's `AndroidManifest.xml`: ``` - + + ``` - React Native <= 0.59 @@ -37,7 +39,8 @@ See [the Android official documentation](https://developer.android.com/guide/com ``` 2. Add VIForegroundService as a service to the application's `AndroidManifest.xml`: ``` - + ``` ### Manual installation (Android only, React Native <= 0.59) @@ -45,21 +48,22 @@ See [the Android official documentation](https://developer.android.com/guide/com - Add `import com.voximplant.foregroundservice.VIForegroundServicePackage;` to the imports at the top of the file - Add `new VIForegroundServicePackage()` to the list returned by the `getPackages()` method 2. Append the following lines to `android/settings.gradle`: - ``` - include ':@voximplant_react-native-foreground-service' + ``` + include ':@voximplant_react-native-foreground-service' project(':@voximplant_react-native-foreground-service').projectDir = new File(rootProject.projectDir, '../node_modules/@voximplant/react-native-foreground-service/android') - ``` + ``` 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: - ``` + ``` implementation project(':@voximplant_react-native-foreground-service') - ``` + ``` 4. Add the FOREGROUND_SERVICE permission to the application's `AndroidManifest.xml`: ``` ``` 5. Add VIForegroundService as a service to the application's `AndroidManifest.xml`: ``` - + ``` ## Demo project diff --git a/android/.project b/android/.project new file mode 100644 index 0000000..79cc823 --- /dev/null +++ b/android/.project @@ -0,0 +1,28 @@ + + + android + Project android created by Buildship. + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.buildship.core.gradleprojectnature + + + + 1605317485573 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/android/src/main/java/com/voximplant/foregroundservice/VIForegroundService.java b/android/src/main/java/com/voximplant/foregroundservice/VIForegroundService.java index facc65a..8df8290 100644 --- a/android/src/main/java/com/voximplant/foregroundservice/VIForegroundService.java +++ b/android/src/main/java/com/voximplant/foregroundservice/VIForegroundService.java @@ -40,4 +40,11 @@ public int onStartCommand(Intent intent, int flags, int startId) { return START_NOT_STICKY; } + + @Override + public void onTaskRemoved(Intent rootIntent) { + super.onTaskRemoved(rootIntent); + stopSelf(); + } + } \ No newline at end of file From 8d2a6d0d996878f77b69824e1aa71c8be5662e9d Mon Sep 17 00:00:00 2001 From: matheus-bg Date: Fri, 13 Nov 2020 22:59:41 -0300 Subject: [PATCH 2/2] Deleting auto generated vscode file. --- android/.project | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 android/.project diff --git a/android/.project b/android/.project deleted file mode 100644 index 79cc823..0000000 --- a/android/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - android - Project android created by Buildship. - - - - - org.eclipse.buildship.core.gradleprojectbuilder - - - - - - org.eclipse.buildship.core.gradleprojectnature - - - - 1605317485573 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - -