Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firebase - Personal Content Indexing

Firebase - Personal Content Indexing

Let your users to search the content immediately by Google Search instead of expecting them to open the application and find their own way. Provide them a shortcut so that they can visit our application even more.

"Personal Content Indexing" is just released with latest version of Firebase, let's talk about how to get our applications ready once it's placed for all. And go through what were the problems and surprises in the way of implementation.

- Presented in GDG Hamburg Android Meetup (02.02.2017)

Yahya Bayramoğlu

February 02, 2017
Tweet

More Decks by Yahya Bayramoğlu

Other Decks in Programming

Transcript

  1. What is Personal Content Indexing? • Public Content Indexing •

    Don’t upload Personal info • On-Device • Indexables - UserActions • Only available “In Apps” tab • Coming Soon! :)
  2. Let’s include App Indexing https://firebase.google.com/docs/app-indexing/android/app To setup Firebase https://firebase.google.com/docs/android/setup classpath

    'com.google.gms:google-services:3.0.0' compile 'com.google.firebase:firebase-appindexing:10.0.1' Done! Go get a beer! Codelabs https://codelabs.developers.google.com/codelabs/app-indexing/index.html
  3. Create an IntentService Google Play Services will call this for

    on-device indexing when • App installed • Updated with Personal Content Indexing Enabled • Periodic calls • Index is lost or corrupted
  4. Update / Remove Indexables Get your App support Deeplink Indexable

    indexable = Indexables.personBuilder() .setUrl(UNIQUE_URL) .setName(user.displayName()) .setImage(user.image()) .setMetadata(new Indexable.Metadata.Builder().setWorksOffline(true)) .build(); Task<Void> task = FirebaseAppIndex.getInstance().update(indexable); Task<Void> task = FirebaseAppIndex.getInstance().remove(UNIQUE_URL); Task<Void> task = FirebaseAppIndex.getInstance().removeAll();
  5. What about RxJava? public Completable remove(String... identifiers) { return Completable.fromEmitter(emitter

    -> firebaseAppIndex.remove(identifiers) .addOnSuccessListener(aVoid -> emitter.onCompleted()) .addOnFailureListener(emitter::onError)); } removeIndexables() .concatWith(retrieveNewData() .flatMap(this::insertToDatabase) .toCompletable()) .concatWith(someMoreAction()) .compose(ioTransformer()) .subscribe(Actions.empty(), Timber::e);
  6. NetworkOnMainThreadException ??? Source: https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/tasks/Task public abstract Task<TResult> addOnSuccessListener (OnSuccessListener<? super

    TResult> listener) Adds a listener that is called if the Task completes successfully. The listener will be called on a shared thread pool. If the Task has already completed successfully, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
  7. Options • Update subscribeOn again on continues stream removeIndexables() .concatWith(retrieveNewData()

    .flatMap(this::insertToDatabase) .toCompletable() .subscribeOn(ioScheduler())) .concatWith(someMoreAction()) .compose(ioTransformer()) .subscribe(Actions.empty(), Timber::e); • Create your own Scheduler from Executer, use onSuccessListener with same Executer • Be creative :)
  8. Google Play Services Version Google Play services out of date.

    Requires 10084000 but found 9879470 Google Play services out of date. Requires 10084000 but found 9879470 Google Play services out of date. Requires 10084000 but found 9879470 private boolean isGooglePlayServicesSufficient() { try { return context.getPackageManager() .getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0) .versionCode >= REQUIRED_GOOGLE_PLAY_SERVICES_VERSION; } catch (NameNotFoundException e) { // There is no GooglePlayServices. OMG! return false; } }
  9. Options • Mission Abort Go get a Beer! public Completable

    remove(String... identifier) { if (!isGooglePlayServicesSufficient()) return Completable.complete(); return Completable.fromEmitter(emitter -> firebaseAppIndex.remove(identifier) .addOnSuccessListener(aVoid -> emitter.onCompleted()) .addOnFailureListener(emitter::onError)); } • Ask user to update • Be nice, do both!
  10. Google needs statistics Action action = new Action.Builder(Action.Builder.VIEW_ACTION) .setObject("Action description",

    UNIQUE_URL) .setMetadata(new Action.Metadata.Builder().setUpload(false)) .build(); FirebaseUserActions.getInstance().start(action); FirebaseUserActions.getInstance().end(action);