Skip to content

This Cordova plugin will start automatically your app after the every boot or the auto-update of your application. You can enable or disable the autostart function in your app.

License

Notifications You must be signed in to change notification settings

alindzon/cordova-plugin-autostart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autostart plugin

This Cordova plugin will start automatically your Android app or service after the every boot or the auto-update of your application. You can enable or disable the autostart function in your app. The plugin is also compatible with PhoneGap Build.

Supported Platforms

  • Android
  • macOS

notes about this fork

  • 1 - no attention paid to macos, only using it for android
  • 2 - added index.d.ts to allow typescript to work specifically wanted it to work with Capacitor
  • 3 - project AndroidaManifest.xml needed these changes to get rid of an execution errro
     <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
    <application ...
            <receiver android:name="com.tonikorin.cordova.plugin.autostart.UserPresentReceiver" android:exported="true" tools:replace="android:exported">
              <intent-filter>
                  <action android:name="android.intent.action.USER_PRESENT" />
              </intent-filter>
          </receiver>
      </application>
    
  • 4 - user must grant Appear on Top permission (having trouble getting this to happen from the app - let me know if you have that working) Without this permission the app loads and then immediatlely is terminated. My app is not a service, it needs to be active to get connected etc..
  • 5 - project app.component.ts edited as follows with added code to move the app to the foreground on startup
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';

declare let cordova: any;
@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {
  constructor(private platform: Platform) {
    this.platform.ready().then(() => {
      cordova.plugins.backgroundMode.enable();
      cordova.plugins.backgroundMode.unlock();
      cordova.plugins.backgroundMode.moveToForeground();
  }
  ,(err) => {console.log('Error moving to the foreground',err)})}
}

Usage

Enable the automatic startup of your app after the boot

cordova.plugins.autoStart.enable();

Not applicable in macOS.

Enable the automatic startup of your service after the boot

cordova.plugins.autoStart.enableService("yourServiceClassName");

In macOS, pass the bundle identifier of a helper application to launch it at startup.

Disable the automatic startup of your app and service after the boot

This is the default action if you have never called the "enable" function.

cordova.plugins.autoStart.disable();

Indication of automatic startup

If the automatic startup has occured, the Android intent includes the attribute "cordova_autostart" with value true. See more instructions to utilize it at related plugins.

macOS helper application

Sandboxed macOS applications are not allowed to write arbitrary files, which means that they cannot register themselves as Launch Agents. Instead, Apple allows the registration of a helper application, embedded in the main app's bundle, to start on boot and launch the main app.

The enableService and disable actions will register/unregister the helper application to launch on startup. It is the caller's responsibility to implement the helper app. See Apple's documentation for more details.

Related plugins

Installation

The plugin can either be installed from git repository, from local file system through the Command-line Interface or cloud based through PhoneGap Build.

Local development environment

From master:

# ~~ from master branch ~~
cordova plugin add https://github.com/ToniKorin/cordova-plugin-autostart.git

from a local folder:

# ~~ local folder ~~
cordova plugin add cordova-plugin-autostart --searchpath path

or to use the latest stable version:

# ~~ stable version ~~
cordova plugin add cordova-plugin-autostart@2.3.0

To remove the plug-in, run the following command:

cordova plugin rm cordova-plugin-autostart

PhoneGap Build

Add the following xml line to your config.xml:

<gap:plugin platform="android" name="cordova-plugin-autostart" version="2.3.0" source="npm"/>

Remarks

  1. Installation to the SD card will prevent the automatic start of your app after the boot. See more details from here.
  2. During the boot your app may start before it has no network connectivity. Your app have to take care of it e.g. using the cordova-plugin-network-information.

History

Check the Change Log.

License

This software is released under the Apache 2.0 License.

© 2015 Toni Korin

About

This Cordova plugin will start automatically your app after the every boot or the auto-update of your application. You can enable or disable the autostart function in your app.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 68.6%
  • Swift 17.1%
  • JavaScript 14.3%