Git Product home page Git Product logo

ti.playservices's Introduction

ti.playservices

To provide Google Play Services for Titanium modules and applications

Requirements

  • Titanium Mobile SDK 7.0.0 or later (release 12/2017)

Example

Add the module as a dependency to your application by adding a <module> item to the <modules> element of your tiapp.xml file:

<ti:app>
  ...
  <modules>
    <module platform="android">ti.playservices</module>
  </modules>
  ...
</ti:app>

Use require() to access the module from JavaScript:

    const PlayServices = require('ti.playservices');

The PlayServices variable is a reference to the module. Make API calls using this reference:

    const playServicesAvailable = PlayServices.isGooglePlayServicesAvailable();

As of version 17.1.0 (only supported by Titanium Mobile SDK 9.0.0 and above), the ti.playservices module will automatically check if Google Play Services is installed and up-to-date on the device upon app startup. If not, the module will prompt the end-user to install/update it. The main app script (ie: app.js or alloy.js) will not be executed until the end-user has successfully installed/updated Google Play Services or if it is already up-to-date.

If you do not want ti.playservices to check Google Play Services on app startup, then you can disable the above mentioned behavior by setting the below property in the tiapp.xml file.

<ti:app xmlns:ti="http://ti.appcelerator.org">
	<property name="ti.playservices.validate.on.startup" type="bool">false</property>
</ti:app>

If you disable the above behavior, then it is highly recommended to detect availability issues yourself as shown below.

const PlayServices = require('ti.playservices');

const win = Ti.UI.createWindow({ backgroundColor: 'gray' });
const btn = Ti.UI.createButton({ title: 'CHECK PLAY SERVICES' });

btn.addEventListener('click', () => {
    PlayServices.makeGooglePlayServicesAvailable((e) => {
        if (e.success) {
            alert(`Play Services: ${PlayServices.GOOGLE_PLAY_SERVICES_VERSION_CODE}`);
            // Use Play Services
        } else {
            alert(`Play Services is not available.`);
        }
    });
});

win.add(btn);
win.open();

To include Play Services libraries with your native module include the module as a dependency by adding a <module> item to the <modules> element of your timodule.xml file:

<ti:module>
  ...
  <modules>
    <module platform="android">ti.playservices</module>
  </modules>
  ...
</ti:module>

For a detailed API example please see android/example/app.js

Build

  1. Create a lib folder in the android directory
  2. Run npm install node . from the updater directory
  3. Run npm install && node . from the updater directory
  4. Run appc run -p android --build-only from the android directory

Author

Axway

License

Apache 2.0

Contributing

Code contributions are greatly appreciated, please submit a new pull request!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.