• This repository has been archived on 18/May/2021
  • Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    Java
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Plugin to support background execution

Start an App Without Showing the Activity

The purpose of this plugin is to enable notifications, alarms, etc to re-start your app and fire callbacks without the app causing any visual cues to the user. In essense, it allows starting an app as an Android service, but does so without the use of an actual service.

Status

Works on iOS and Android.

iOS values for resumeType limited to: '', 'launch', 'normal', 'normal-launch'

Usage

To see it in action, try the example app.

For how to create your own plugin that uses it, look at cordova-plugin-chrome-apps-notifications or cordova-plugin-chrome-apps-alarms

cordova.backgroundapp.resumeType (string)

After the deviceready event, this will either be:

  • '' - When started as a service.
  • 'launch' - When started normally.

After a resume event, this will be one of:

  • 'normal' - Triggered by an external intent (launcher / task switcher). App was running normally, but had been backgrounded.
  • 'normal-launch' - Triggered by an external intent (launcher / task switcher). App was running as a service.
  • 'programmatic' - Triggered by a call to BackgroundActivity.launchForeground(). App was running normally, but had been backgrounded.
  • 'programmatic-launch' - Triggered by a call to `BackgroundActivity. App was running as a service.

The normal way to use this plugin:

document.addEventListener("deviceready", function() {
    if (cordova.backgroundapp.resumeType == 'launch') {
        renderUi();
    }
}, false);
document.addEventListener("resume", function() {
    if (cordova.backgroundapp.resumeType == 'normal-launch') {
        renderUi();
    } else if (cordova.backgroundapp.resumeType == 'programmatic-launch') {
        // You launched programatically (through cordova.backgroundapp.show() perhaps)
        // so you should have already called renderUi() from where you called .show().
    }
}, false);

cordova.backgroundapp.show()

Brings the app to the foreground. E.g. Call this in response to a user clicking on a notification.

This symbol will be null on iOS, since iOS has not yet implemented this functionality.

Implementation Details

The goal is ultimately to be able to run the app in an Android service, but because many plugins utilize CordovaInterface.getActivity(), a background Activity rather than a Service is more viable.

  • Uses gradle build rule to remove your default <intent-filter>
  • Uses a BackgroundLauncherActivity to recieve launch intent and start your main activity.
  • If you are an already shipping app, you should use an <activity-alias> to make your previous main activity point to BackgroundLauncherActivity, and then rename your main activity to not conflict with the alias. This is so that launcher shortcuts continue to function correctly.

Known Issues

  • When the app goes from not running -> running in background, if you are currently in the task switcher, the task switcher will close.
  • On Lollipop, backgrounded app shows in recents list when no other recents exists (fixed in MR1)

Release Notes

2.0.2 (May 14, 2015)

  • iOS: Fix crash on resume (Issue #1)

2.0.1 (May 13, 2015)

  • Fix cordova.backgroundapp.resumeType being 'launch' when running in background on Android
  • Added sample app to git repo

2.0.0 (April 29, 2015)

  • Introduced cordova.backgroundapp.resumeType and cordova.backgroundapp.show()
  • Rewrote Android implementation to not require translucent theme
  • Minimal iOS support added (basic resumeType values only)

1.0.0 (March 2015)

  • Initial release

More Repositories

1

mobile-chrome-apps

Chrome apps on Android and iOS
Python
2,501
star
2

chrome-cordova

Chrome APIs and integration layer for running Chrome Apps on mobile using Apache Cordova.
Objective-C
176
star
3

cordova-plugin-zip

Zip plugin for Cordova apps
C
168
star
4

cordova-plugin-service-worker

Objective-C
163
star
5

harness

Scripts for building the mobile Chrome Apps version of Apache's Cordova App Harness.
Java
104
star
6

mobile-chrome-app-samples

JavaScript
86
star
7

cordova-plugin-chrome-apps-sockets-udp

JavaScript
80
star
8

google-play-services

A Cordova plugin for Android that adds Google Play Services
Java
51
star
9

cordova-plugin-chrome-apps-sockets-tcp

JavaScript
44
star
10

cordova-plugin-service-worker-background-sync

Cordova Service Worker Background Sync Plugin
JavaScript
35
star
11

workshop-cca-eh

HTML
29
star
12

cordova-plugin-google-payments

Java
13
star
13

cordova-plugin-chrome-apps-usb

Java
13
star
14

cordova-plugin-chrome-apps-sockets-tcpServer

Java
12
star
15

cordova-plugin-chrome-apps-socket

JavaScript
12
star
16

cordova-plugin-chrome-apps-bootstrap

Plugin to run a Chrome app on top of Cordova
JavaScript
11
star
17

cordova-plugin-service-worker-geofencing

Cordova Geofencing Plugin
JavaScript
11
star
18

cordova-plugin-service-worker-notifications

Cordova Notification Plugin
JavaScript
11
star
19

cordova-plugin-service-worker-push

Push plugin for Cordova service worker
Objective-C
11
star
20

cordova-plugin-chrome-apps-alarms

JavaScript
10
star
21

cordova-plugin-chrome-apps-notifications

JavaScript
10
star
22

cordova-plugin-chrome-apps-bluetooth

Objective-C
10
star
23

cordova-plugin-chrome-apps-bluetoothLowEnergy

Java
9
star
24

cordova-plugin-chrome-apps-identity

JavaScript
9
star
25

cordova-plugin-android-support-v4

Adds the android-support-v4.jar to your project.
8
star
26

cordova-plugin-okhttp

Java
8
star
27

android-support

A Cordova plugin for Android that adds Android support libraries.
7
star
28

cordova-plugin-chrome-apps-gcm

JavaScript
5
star
29

syncNote

Demo app for chrome.syncFileSystem API
JavaScript
5
star
30

AndroidApkTemplate

JavaScript
5
star
31

cordova-plugin-chrome-apps-system-memory

Objective-C
5
star
32

cordova-plugin-chrome-apps-bluetoothSocket

Java
5
star
33

cordova-plugin-chrome-apps-system-cpu

Objective-C
5
star
34

cordova-plugin-chrome-apps-audioCapture

JavaScript
5
star
35

cca-push

Standalone Node tool to package and push Chrome apps to the Chrome ADT on mobile devices
JavaScript
4
star
36

cordova-plugin-chrome-apps-storage

JavaScript
4
star
37

cordova-plugin-chrome-apps-test-framework

Shared infrastructure for tests of Chrome Apps for Mobile plugins
JavaScript
3
star
38

cordova-plugin-chrome-apps-power

Java
3
star
39

cordova-plugin-chrome-apps-fileSystem

Objective-C
3
star
40

cordova-plugin-android-support-v7-appcompat

Adds the android-support-v7-appcompat.jar to your project.
3
star
41

cordova-plugin-chrome-apps-navigation

Objective-C
3
star
42

cordova-plugin-google-open-source-ios

Objective-C
3
star
43

experimental

For our early experiments
Objective-C
3
star
44

cordova-plugin-chrome-apps-videoCapture

JavaScript
2
star
45

cordova-plugin-chrome-apps-system-network

Objective-C
2
star
46

cordova-plugin-android-support-v7-mediarouter

Adds the android-support-v7-mediarouter.jar to your project.
2
star
47

cordova-plugin-chrome-apps-system-storage

Java
2
star
48

cordova-plugin-google-plus-ios

Cordova plugin for Google+ iOS SDK
Objective-C
2
star
49

cordova-plugin-blob-constructor-polyfill

JavaScript
2
star
50

sw2cdv

JavaScript
2
star
51

cordova-plugin-chrome-apps-i18n

JavaScript
2
star
52

cordova-plugin-customevent-polyfill

JavaScript
1
star
53

cordova-plugin-chrome-apps-common

JavaScript
1
star
54

cordova-plugin-xhr-blob-polyfill

JavaScript
1
star
55

cordova-plugin-chrome-apps-system-display

Java
1
star
56

cordova-plugin-chrome-apps-idle

JavaScript
1
star
57

cordova-plugin-chrome-apps-iosSocketsCommon

1
star
58

cordova-plugin-chrome-apps-runtime

JavaScript
1
star
59

cordova-plugin-chrome-apps-pushMessaging

Objective-C
1
star