Introduction

    Integration of Pollfish in an Android application is simple, and is described in detail in the official guide here: Pollfish Android Documentation

    1. as a Publisher at Pollfish website, create a new app and grab its API key from the dashboard
    2. Download Pollfish SDK (either Google Play or Universal) or reference it in your gradle file through jcenter()
    3. Add relevant Pollfish aar or jar file in your project, import relevant classes and add required permissions in your app’s manifest as described in the
    4. Call Pollfish init function in your onResume of your AndroidLauncher

    Optional Steps

    You can listen to Pollfish listeners by implementing them in your AndroidLauncher, for example:

    1. @Override
    2. public void onPollfishSurveyCompleted(boolean playfulSurveys , int surveyPrice) {
    3. Log.d("Pollfish", "Pollfish survey completed - Playful survey: " + playfulSurveys + " with price: " + surveyPrice);
    4. }

    In your and in your AndroidLauncher.java file:

    1. package com.mygdx.game;
    2. import com.badlogic.gdx.ApplicationAdapter;
    3. import com.badlogic.gdx.Gdx;
    4. import com.badlogic.gdx.graphics.GL20;
    5. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    6. import com.badlogic.gdx.scenes.scene2d.InputEvent;
    7. import com.badlogic.gdx.scenes.scene2d.Stage;
    8. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
    9. import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
    10. import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
    11. public class MyGdxGame extends ApplicationAdapter {
    12. private SpriteBatch batch;
    13. private Skin skin;
    14. private Stage stage;
    15. // Define an interface for your various callbacks to the android launcher
    16. public interface MyPollfishCallbacks {
    17. public void showPollfish();
    18. public void hidePollfish();
    19. }
    20. // Local variable to hold the callback implementation
    21. private MyPollfishCallbacks myPollfishCallbacks;
    22. // ** Additional **
    23. public void setMyPollfishCallbacks(MyPollfishCallbacks callback) {
    24. myPollfishCallbacks = callback;
    25. }
    26. @Override
    27. public void create() {
    28. batch = new SpriteBatch();
    29. skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    30. stage = new Stage();
    31. final TextButton showBtn = new TextButton("Show", skin, "default");
    32. showBtn.setWidth(400f);
    33. showBtn.setHeight(100f);
    34. showBtn.setPosition(Gdx.graphics.getWidth() /2 - 600f, Gdx.graphics.getHeight()/2 - 10f);
    35. showBtn.addListener(new ClickListener(){
    36. @Override
    37. public void clicked(InputEvent event, float x, float y){
    38. if(myPollfishCallbacks!=null){
    39. myPollfishCallbacks.showPollfish();
    40. }
    41. }
    42. });
    43. final TextButton hideBtn = new TextButton("Hide", skin, "default");
    44. hideBtn.setWidth(400f);
    45. hideBtn.setHeight(100f);
    46. hideBtn.setPosition(Gdx.graphics.getWidth() /2 + 300f, Gdx.graphics.getHeight()/2 - 10f);
    47. hideBtn.addListener(new ClickListener(){
    48. @Override
    49. if(myPollfishCallbacks!=null){
    50. }
    51. }
    52. });
    53. stage.addActor(showBtn);
    54. stage.addActor(hideBtn);
    55. Gdx.input.setInputProcessor(stage);
    56. }
    57. @Override
    58. public void dispose() {
    59. batch.dispose();
    60. }
    61. @Override
    62. public void render() {
    63. Gdx.gl.glClearColor(1, 0, 1, 1);
    64. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    65. batch.begin();
    66. stage.draw();
    67. batch.end();
    68. }
    69. @Override
    70. public void resize(int width, int height) {
    71. }
    72. @Override
    73. public void pause() {
    74. }
    75. @Override
    76. public void resume() {
    77. }

    It happens that time had past since you initialized Pollfish and a survey is received. If you want to check if survey is still avaialble on your device and has not expired you can check by calling: