use of com.google.firebase.appindexing.Indexable in project quickstart-android by firebase.
the class MainActivity method onStart.
// [END handle_intent]
// [START app_indexing_view]
@Override
public void onStart() {
super.onStart();
if (articleId != null) {
final Uri BASE_URL = Uri.parse("https://www.example.com/articles/");
final String APP_URI = BASE_URL.buildUpon().appendPath(articleId).build().toString();
Indexable articleToIndex = new Indexable.Builder().setName(TITLE).setUrl(APP_URI).build();
Task<Void> task = FirebaseAppIndex.getInstance().update(articleToIndex);
// If the Task is already complete, a call to the listener will be immediately
// scheduled
task.addOnSuccessListener(MainActivity.this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "App Indexing API: Successfully added " + TITLE + " to index");
}
});
task.addOnFailureListener(MainActivity.this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "App Indexing API: Failed to add " + TITLE + " to index. " + exception.getMessage());
}
});
// log the view action
Task<Void> actionTask = FirebaseUserActions.getInstance().start(Actions.newView(TITLE, APP_URI));
actionTask.addOnSuccessListener(MainActivity.this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "App Indexing API: Successfully started view action on " + TITLE);
}
});
actionTask.addOnFailureListener(MainActivity.this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "App Indexing API: Failed to start view action on " + TITLE + ". " + exception.getMessage());
}
});
}
}
Aggregations