Courtesy: GitHub

GcmNetworkManager Quickstart

This sample demonstrates how to use the GcmNetworkManager API.

Introduction

GcmNetworkManager can be used to reliably schedule network operations in your application based on time, charging status, connectivity, and other variables. GcmNetworkManager is similar to the Android JobScheduler API which is available on all Android devices running Lollipop or higher, however GcmNetworkManager is available on any device running Google Play Services.

For more information on GcmNetworkManager, visit: https://developers.google.com/cloud-messaging/network-manager

Prerequisites

In order to run this quickstart sample you will need:

  • Android Studio v1.4 or higher
  • An Android device with Google Play Services 8.3 or higher
  • A USB cable

Getting Started

To run the quickstart application:

  • Import the project into Android Studio
  • Connect your Android device over USB, with USB debugging enabled
  • Click Run > Run 'app'

Support

compileSdkVersion 22

applicationId "com.google.example.gcmnetworkmanagerquickstart"

minSdkVersion 9

targetSdkVersion 22

versionCode 1

versionName "1.0"

compile fileTree(dir: 'libs', include: ['*.jar'])

testCompile 'junit:junit:4.12'

compile 'com.android.support:appcompat-v7:22.1.0'

compile 'com.squareup.okhttp:okhttp:2.7.0'

compile 'com.google.android.gms:play-services-gcm:8.3.0'

package com.google.example.gcmnetworkmanagerquickstart

uses-permission

  • android.permission.CHANGE_WIFI_STATE
  • android.permission.INTERNET

MainActivity

MyTaskService