• This repository has been archived on 27/Apr/2021
  • Stars
    star
    471
  • Rank 90,204 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated over 6 years ago

Reviews

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

Repository Details

Simple wrapper library for Google APIs

EasyGoogle

Project status

status: inactive

This project is no longer actively maintained, and remains here as an archive of this work.

EasyGoogle was created as an experimental improvement to the developer experience for certain Google APIs. In the time since its creation, most of these APIs have improved (and many in ways that resemble EasyGoogle). For this reason it no longer makes sense to maintain this library. Thank you to everyone who submitted issues or gave feedback, your thoughts influenced API development at Google.

Introduction

EasyGoogle is a wrapper library to simplify basic integrations with Google Play Services. The library wraps the following APIs (for now):

Installation

EasyGoogle is installed by adding the following dependency to your build.gradle file:

dependencies {
  compile 'pub.devrel:easygoogle:0.2.5+'
}

Usage

Enabling Services

Before you begin, visit this page to select Google services and add them to your Android app. Make sure to enable any services you plan to use and follow all of the steps, including modifying your build.gradle files to enable the google-services plugin.

Once you have a google-services.json file in the proper place you can proceed to use EasyGoogle.

Basic

EasyGoogle makes use of Fragments to manage the lifecycle of the GoogleApiClient, so any Activity which uses EasyGoogle must extend FragmentActivity.

All interaction with EasyGoogle is through the Google class, which is instantiated like this:

public class MainActivity extends AppCompatActivity {

  private Google mGoogle;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogle = new Google.Builder(this).build();
  }

}

Of course, instantiating a Google object like this won't do anything at all, you need to enable features individually.

Sign-In

To enable Google Sign-In, call the appropriate method on Google.Builder and implement the SignIn.SignInListener interface:

 public class MainActivity extends AppCompatActivity implements
   SignIn.SignInListener {

   private Google mGoogle;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);

     // This is optional, pass 'null' if no ID token is required.
     String serverClientId = getString(R.string.default_web_client_id);

     mGoogle = new Google.Builder(this)
       .enableSignIn(this, serverClientId)
       .build();
   }

   @Override
   public void onSignedIn(GoogleSignInAccount account) {
       // Sign in was successful.
   }

   @Override
   public void onSignedOut() {
       // Sign out was successful.
   }

   @Override
   public void onSignInFailed() {
       // Sign in failed for some reason and should not be attempted again
       // unless the user requests it.
   }

 }

Then, use the SignIn object from mGoogle.getSignIn() to access API methods like SignIn#getCurrentUser(), SignIn#signIn, and SignIn#signOut.

Cloud Messaging

To enable Cloud Messaging, you will have to implement a simple Service in your application.

First, pick a unique permission name and make the following string resource in your strings.xml file. It is important to pick a unique name:

<string name="gcm_permission">your.unique.gcm.permission.name.here</string>

Next, add the following to your AndroidManifest.xml inside the application tag, making sure that the value of the android:permission element is the same value you specified in your strings.xml file above:

 <!-- This allows the app to receive GCM through EasyGoogle -->
 <service
     android:name=".MessagingService"
     android:enabled="true"
     android:exported="false"
     android:permission="your.unique.gcm.permission.name.here" />

Next, add the following permission to your AndroidManifest.xml file before the application tag, replacing <your-package-name> with your Android package name:

    <permission android:name="<your-package-name>.permission.C2D_MESSAGE"
                android:protectionLevel="signature" />
    <uses-permission android:name="<your-package-name>.permission.C2D_MESSAGE" />

Then implement a class called MessagingService that extends EasyMessageService. Below is one example of such a class:

public class MessagingService extends EasyMessageService {

  @Override
  public void onMessageReceived(String from, Bundle data) {
      // If there is a running Activity that implements MessageListener, it should handle
      // this message.
      if (!forwardToListener(from, data)) {
          // There is no active MessageListener to get this, I should fire a notification with
          // a PendingIntent to an activity that can handle this.
          PendingIntent pendingIntent = createMessageIntent(from, data, MainActivity.class);
          Notification notif = new NotificationCompat.Builder(this)
                  .setContentTitle("Message from: " + from)
                  .setContentText(data.getString("message"))
                  .setSmallIcon(R.mipmap.ic_launcher)
                  .setContentIntent(pendingIntent)
                  .setAutoCancel(true)
                  .build();

          NotificationManager notificationManager =
                  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          notificationManager.notify(0, notif);
      }
  }

  @Override
  public void onNewToken(String token) {
      // Send a registration message to the server with our new token
      String senderId = getString(R.string.gcm_defaultSenderId);
      sendRegistrationMessage(senderId, token);
  }
}

Note the use of the helper methods forwardToListener and createMessageIntent, which make it easier for you to either launch an Activity or create a Notification to handle the message.

The forwardToListener method checks to see if there is an Activity that implements Messaging.MessagingListener in the foreground. If there is, it sends the GCM message to the Activity to be handled. To implement Messaging.MessagingListener, call the appropriate method on Google.Builder in your Activity and implement the interface:

public class MainActivity extends AppCompatActivity implements
  Messaging.MessagingListener {

  private Google mGoogle;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogle = new Google.Builder(this)
      .enableMessaging(this, getString(R.string.gcm_defaultSenderId))
      .build();
  }

  @Override
  public void onMessageReceived(String from, Bundle message) {
      // GCM message received.
  }
}

Then, use the Messaging object from mGoogle.getMessaging() to access API methodslike Messaging#send.

App Invites

To enable App Invites, call the appropriate method on Google.Builder and implement the AppInvites.AppInviteListener interface:

public class MainActivity extends AppCompatActivity implements
  AppInvites.AppInviteListener {

  private Google mGoogle;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogle = new Google.Builder(this)
      .enableAppInvites(this)
      .build();
  }

  @Override
  public void onInvitationReceived(String invitationId, String deepLink) {
      // Invitation recieved in the app.
  }

  @Override
  public void onInvitationsSent(String[] ids) {
      // The user selected contacts and invitations sent successfully.
  }

  @Override
  public void onInvitationsFailed() {
      // The user either canceled sending invitations or they failed to
      // send due to some configuration error.
  }

}

Then, use the AppInvites object from mGoogle.getAppInvites() to access API methods like AppInvites#sendInvitation.

SmartLock for Passwords

To enable Smart Lock for Passwords, call the appropriate method on Google.Builder and implement the SmartLock.SmartLockListener interface:

public class MainActivity extends AppCompatActivity implements
  SmartLock.SmartLockListener {

  private Google mGoogle;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogle = new Google.Builder(this)
      .enableSmartLock(this)
      .build();
  }

  @Override
  public void onCredentialRetrieved(Credential credential) {
    // Successfully retrieved a Credential for the current device user.
  }

  @Override
  public void onShouldShowCredentialPicker() {
    // In order to retrieve a Credential, the app must show the picker dialog
    // using the SmartLock#showCredentialPicker() method.
  }

  @Override
  public void onCredentialRetrievalFailed() {
    // The user has no stored credentials, or the retrieval operation failed or
    // was canceled.
  }

}

Then, use the SmartLock object from mGoogle.getSmartLock() to access API methods like SmartLock#getCredentials() and SmartLock#save().

Advanced Usage

If you would like to perform some action using one of the enabled Google services but it is not properly wrapped by the EasyGoogle library, just call Google#getGoogleApiClient() to get access to the underlying GoogleApiClient held by the Google object.

More Repositories

1

code-prettify

An embeddable script that makes source-code snippets in HTML prettier.
JavaScript
5,768
star
2

chromedeveditor

Chrome Dev Editor is a developer tool for building apps on the Chrome platform - Chrome Apps and Web Apps, in JavaScript or Dart. (NO LONGER IN ACTIVE DEVELOPMENT)
Dart
2,924
star
3

android-Camera2Basic

Migrated:
Java
2,863
star
4

android-ConstraintLayoutExamples

Migrated:
Java
2,571
star
5

firebase-jobdispatcher-android

DEPRECATED please see the README.md below for details.
Java
1,796
star
6

vrview

Library for embedding immersive media into traditional websites.
JavaScript
1,709
star
7

tiger

Java
1,645
star
8

flipjs

A helper library for doing FLIP animations.
JavaScript
1,409
star
9

android-PictureInPicture

Migrated:
Java
1,393
star
10

android-FingerprintDialog

Migrated:
Java
1,375
star
11

observe-js

A library for observing Arrays, Objects and PathValues
JavaScript
1,357
star
12

PyDrive

Google Drive API Python wrapper library
Python
1,304
star
13

js-marker-clusterer

A marker clustering library for the Google Maps JavaScript API v3.
JavaScript
1,279
star
14

android-RuntimePermissions

This sample has been deprecated/archived. Check this repo for related samples:
Java
1,263
star
15

android-Camera2Video

Migrated:
Java
1,201
star
16

chromium-webview-samples

Useful examples for Developing apps with the Chromium based WebView
Java
1,173
star
17

androidtv-Leanback

Migrated:
Java
1,148
star
18

caja

Caja is a tool for safely embedding third party HTML, CSS and JavaScript in your website.
Java
1,126
star
19

android-ui-toolkit-demos

Migrated:
Java
1,118
star
20

android-ScreenCapture

Migrated:
Java
1,021
star
21

android-BluetoothChat

Migrated:
Java
986
star
22

android-BluetoothLeGatt

Migrated:
Java
911
star
23

sample-media-pwa

A sample video-on-demand media Progressive Web App
JavaScript
889
star
24

ChromeWebLab

The Chrome Web Lab for Makers, Hackers and everyone
JavaScript
877
star
25

big-rig

A proof-of-concept Performance Dashboard, CLI and Node module
CSS
857
star
26

android-instant-apps

Migrated:
Java
847
star
27

cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
JavaScript
827
star
28

guitar-tuner

A web-based guitar tuner
JavaScript
822
star
29

android-JobScheduler

This sample has been deprecated/archived. Check this repo for related samples:
Java
773
star
30

flashlight

A pluggable integration with ElasticSearch to provide advanced content searches in Firebase.
JavaScript
757
star
31

friendlypix

FriendlyPix is a cross-platform Firebase example app
726
star
32

voice-memos

A Progressive Web App for recording and playing back voice memos.
JavaScript
724
star
33

android-audio-high-performance

We now recommend you use the Oboe libraries:
C++
715
star
34

android-EmojiCompat

Migrated:
Java
707
star
35

android-RecyclerView

Migrated:
Java
675
star
36

ios-swift-chat-example

FireChat implemented in Swift!
Objective-C
673
star
37

leanback-showcase

Migrated:
Java
639
star
38

android-transition-examples

Migrated:
581
star
39

geofire

Realtime location queries with Firebase
569
star
40

drive-music-player

Fully client side Music Player for Google Drive
JavaScript
566
star
41

android-viewpager2

Migrated:
552
star
42

topeka

quiz app
HTML
532
star
43

science-journal-ios

Use the sensors in your mobile devices to perform science experiments. Science doesn’t just happen in the classroom or labβ€”tools like Science Journal let you see how the world works with just your phone.
Swift
532
star
44

android-PdfRendererBasic

Migrated:
Java
522
star
45

science-journal

Use the sensors in your mobile devices to perform science experiments. Science doesn’t just happen in the classroom or labβ€”tools like Science Journal let you see how the world works with just your phone.
Java
508
star
46

tango-examples-java

Example projects for Project Tango [deprecated] Java API
Java
500
star
47

AndroidChat

Demonstrates using the Firebase Android SDK to back a ListView.
Java
499
star
48

android-nearby

Migrated:
Java
494
star
49

android-play-places

Deprecated:
Java
479
star
50

tango-examples-unity

Project Tango [deprecated] UnitySDK Example Projects
C#
475
star
51

firefeed

JavaScript
461
star
52

android-dynamic-features

Migrated:
Kotlin
460
star
53

android-MediaBrowserService

This sample is deprecated.
Java
457
star
54

graphd

The Metaweb graph repository server
C
445
star
55

drive-zipextractor

Extract (decompress) ZIP files into Google Drive using the Google Drive API
JavaScript
435
star
56

android-AutofillFramework

Migrated:
Java
432
star
57

webplatform-samples

HTML5 Samples/Demos
430
star
58

cloud-functions-go

Unofficial Native Go Runtime for Google Cloud Functions
Go
427
star
59

android-unsplash

Deprecated:
424
star
60

android-MultiWindowPlayground

Migrated:
Java
418
star
61

appengine-flask-skeleton

A skeleton for creating Python applications using the Flask framework on App Engine
Python
416
star
62

angularfire-seed

Seed project for AngularFire apps
JavaScript
412
star
63

node-big-rig

A CLI version of Big Rig
JavaScript
410
star
64

firebase-dart

Dart wrapper for Firebase
Dart
409
star
65

android-Camera2Raw

Migrated:
Java
386
star
66

js-store-locator

A library for easily building store-locator-type applications using the Google Maps JavaScript API v3
JavaScript
380
star
67

ADBPlugin

Google Chrome Extension with ADB Daemon
C++
372
star
68

android-fit

Migrated:
Java
372
star
69

android-NotificationChannels

This sample has been deprecated/archived. Check this repo for related samples:
Java
369
star
70

appengine-php-wordpress-starter-project

Starter project for running WordPress on Google Cloud Platform
PHP
368
star
71

android-ActivitySceneTransitionBasic

Migrated:
368
star
72

android-text

Migrated:
Kotlin
363
star
73

android-XYZTouristAttractions

Migrated:
356
star
74

firebase-angular-starter-pack

A Firebase + AngularJS Starter Pack
JavaScript
348
star
75

android-OurStreets

Migrated:
345
star
76

tango-examples-c

JNI example projects for Project Tango [deprecated] C-API
C++
334
star
77

simian

Simian is an enterprise-class Mac OS X software deployment solution. Google App Engine hosted server, with a client powered by the Munki open-source project.
Python
334
star
78

OpenInChrome

Open in Chrome
Objective-C
333
star
79

android-DownloadableFonts

Migrated:
Java
319
star
80

friendlypix-web

FriendlyPix is a cross-platform Firebase example app - This is the web version
JavaScript
312
star
81

pywebsocket

WebSocket server and extension for Apache HTTP Server for testing
Python
310
star
82

android-DarkTheme

migrated:
Java
302
star
83

firereader

Firereader: A feed reader built with Firebase and AngularJS
JavaScript
301
star
84

android-WatchFace

Migrated:
300
star
85

android-MediaRecorder

Migrated:
Java
299
star
86

backbonefire

Backbone bindings for Firebase
JavaScript
291
star
87

TemplateBinding

TemplateBinding Prolyfill
JavaScript
291
star
88

firebase-login-demo-android

Java
280
star
89

Firebase-Unity

Objective-C
279
star
90

seed-element

Polymer element boilerplate
HTML
278
star
91

firebase-util

An experimental toolset for Firebase
JavaScript
276
star
92

android-NavigationDrawer

This sample has been deprecated/archived. Check this repo for related samples:
Java
276
star
93

android-DisplayingBitmaps

Migrated:
Java
272
star
94

wReader-app

RSS Reader written using AngularJS
JavaScript
271
star
95

gcm-playground

CSS
268
star
96

android-CardView

Migrated:
Java
265
star
97

soundstagevr

C#
263
star
98

ShadowDOM

ShadowDOM Polyfill
JavaScript
263
star
99

android-credentials

Migrated:
Java
260
star
100

gamebuilder

Game Builder is an application that allows users to create games with little or no coding experience.
C#
253
star