{"_id":"58255f706ec2ef0f00f4778b","parentDoc":null,"user":"56caca84245b841300806def","version":{"_id":"56cacb1cc675f50b00a4b61c","project":"56cacb1bc675f50b00a4b619","__v":14,"createdAt":"2016-02-22T08:47:24.528Z","releaseDate":"2016-02-22T08:47:24.528Z","categories":["56cacb1dc675f50b00a4b61d","56cc10aaca43550b0028125a","56cc10b7b4cbcf0b004a5df9","56cc1bb2272aa4130002ccd2","56cc5834b4cbcf0b004a5f8b","56cda18bface161300dae13b","56d51f2873dcd20b00fb87bb","56fbe0610023171700b96105","57658310c176520e00ea9076","5772bdd48c48e00e00503638","577c1dfe87acf617003c3fcd","579525172979790e00771a15","582b4661cdfdc125000c8684","586365cedfe6cc3700a7be63"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"__v":0,"category":{"_id":"5772bdd48c48e00e00503638","project":"56cacb1bc675f50b00a4b619","__v":0,"version":"56cacb1cc675f50b00a4b61c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-06-28T18:11:32.499Z","from_sync":false,"order":3,"slug":"android-sdk","title":"Android SDK"},"project":"56cacb1bc675f50b00a4b619","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-11-11T06:04:32.103Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Rewards fulfilment service provides you with real rewards that can be awarded to your users. This allows you to plan strategic and tactical campaign to engage your users and reward them on reaching milestones\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Initialization\"\n}\n[/block]\nAdd the following to your **AndroidManifest.xml** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<!-Required to fetch the reward from the Codemojo Servers-->\\n<uses-permission android:name=\\\"android.permission.INTERNET\\\" />\\n\\n<!--Required to access the Advertisement ID & Coarse locale of the user-->\\n<uses-permission android:name=\\\"android.permission.READ_PHONE_STATE\\\" />\\n\\n<!--Optional-->\\n<uses-permission android:name=\\\"android.permission.ACCESS_COARSE_LOCATION\\\" />\\n\\n<application ...>\\n  ...\\n  <activity android:name=\\\"io.codemojo.sdk.ui.AvailableRewardsActivity\\\" />\\n  <activity android:name=\\\"io.codemojo.sdk.ui.RewardDetailsActivity\\\" />\\n  ...\\n</application>\\n\",\n      \"language\": \"xml\",\n      \"name\": \"AndroidManifest.xml\"\n    }\n  ]\n}\n[/block]\nAdd the following to your **build.gradle** file or download the SDK from [here](https://github.com/codemojo-dr/startkit-android-sdk)\n[block:html]\n{\n  \"html\": \"<a target=\\\"_blank\\\" href='https://bintray.com/codemojo/maven/sdk/_latestVersion'><img src='https://api.bintray.com/packages/codemojo/maven/sdk/images/download.svg'></a>\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"dependencies {\\n  compile 'io.codemojo.sdk:sdk:1.0.5+'\\n}\",\n      \"language\": \"groovy\",\n      \"name\": \"build.gradle\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Your First Reward\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Codemojo mojo = new Codemojo(activity_context, \\\"your_client_app_token\\\", \\\"user_id\\\", false);\\n\\nmojo.initRewardsService(\\\"your_app_id_from_codemojo\\\");\\n\\n// Configuration for the UI Screen\\nRewardsScreenSettings settings = new RewardsScreenSettings();\\n\\n// Testing\\nsettings.setTesting(true);\\n\\n// Location India\\nsettings.setLocale(\\\"in\\\");\\n\\n// Launch the Rewards screen\\nmojo.launchAvailableRewardsScreen(settings, this);\\n\",\n      \"language\": \"java\",\n      \"name\": \"Reward your users\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Alternative method for launching the Rewards flow\"\n}\n[/block]\nThe SDK handles the entire UI required for rewarding the user which is customizable to fit to the look & feel of your App. This includes two screens\n\n  * Rewards Screen - that shows the available rewards - \n  * Reward Details Screen - that shows the fine print of the reward with a configurable option to Grab the reward from the same screen\n  * Milestones Screen - that allows you to show the milestones associated to unlock the rewards\n\n**[Click here for details on Rewards Screen Settings](http://docs.codemojo.io/v1/page/android-rewards-screen-settings)**\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Testing Environment\",\n  \"body\": \"When you are testing the rewards system for your app, it is important to set the Testing parameter to true\"\n}\n[/block]\n## Rewarding the Users \n\nSimplest way to show the Rewards screen to the user will be the following way. Codemojo SDK offers you a wrapper thats lets you gracefully handle Rewards availability\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Map<String, String> filters = new HashMap<>();\\nfilters.put(\\\"testing\\\", \\\"true\\\");\\nfilters.put(\\\"locale\\\", \\\"in\\\");\\n\\nmojo.getRewardsService().onRewardsAvailable(\\\"\\\", filters, new RewardsAvailability() {\\n\\n    ProgressDialog progressDialog;\\n\\n    :::at:::Override\\n    public void processing() {\\n        progressDialog = ProgressDialog.show(ChooserActivity.this, \\\"\\\", \\\"One moment please...\\\");\\n        progressDialog.setCancelable(true);\\n    }\\n\\n    @Override\\n    public void available(List<BrandReward> rewards) {\\n        progressDialog.dismiss();\\n        RewardsScreenSettings settings = new RewardsScreenSettings();\\n\\n       settings.setAllowGrab(true);\\n       \\n       // Testing\\n        settings.setTesting(true);\\n      \\n      // Title theme\\n      settings.setThemeTitleColor(R.color.white);\\n      settings.setThemeTitleStripeColor(R.color.colorPrimary);\\n\\n      // Button theme\\n      settings.setThemeButtonColor(R.color.colorAccent);\\n      settings.setThemeAccentFontColor(R.color.white);\\n      \\n       // Launch the Rewards screen\\n        mojo.launchAvailableRewardsScreen(rewards, settings, ChooserActivity.this);\\n    }\\n\\n    @Override\\n    public void unavailable() {\\n        progressDialog.dismiss();\\n    }\\n  \\n    @Override\\n    public void grabbed(Intent data) {\\n\\n    }\\n\\n    @Override\\n    public void error(String error) {\\n\\n    }\\n\\n});\\n\",\n      \"language\": \"java\",\n      \"name\": \"Rewarding\"\n    }\n  ]\n}\n[/block]\n## Showing available Rewards & Milestones to the users\n\nShowing the grab screen is good, but ideally you would want your users to know what they will be getting and when. The SDK allows you to do this with a few modification to the previous process\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Map<String, String> filters = new HashMap<>();\\nfilters.put(\\\"testing\\\", \\\"true\\\");\\nfilters.put(\\\"locale\\\", \\\"in\\\");\\n\\nmojo.getRewardsService().onRewardsAvailable(null, filters, new RewardsAvailability() {\\n    ProgressDialog progressDialog;\\n\\n    @Override\\n    public void processing() {\\n        progressDialog = ProgressDialog.show(ChooserActivity.this, \\\"\\\", \\\"One moment please...\\\");\\n        progressDialog.setCancelable(true);\\n    }\\n\\n    @Override\\n    public void available(List<BrandReward> rewards) {\\n        progressDialog.dismiss();\\n        RewardsScreenSettings settings = new RewardsScreenSettings();\\n\\n      /*\\n       * HERE IS WHERE YOU WILL SET IT TO VIEW-ONLY MODE\\n       */\\n       settings.setAllowGrab(false);\\n       \\n      /*\\n       * SET THE MILESTONES\\n       */\\n      ArrayList<Milestone> milestones = new ArrayList<>();\\n      milestones.add(new Milestone(0, \\\"Each 50th time you open the app\\\"));\\n      milestones.add(new Milestone(0, \\\"Every 10th time you post a facebook update\\\"));\\n      milestones.add(new Milestone(0, \\\"Every time you refer it to your contacts\\\"));\\n      settings.setMileStones(milestones);\\n\\n       // Testing\\n        settings.setTesting(true);\\n      \\n      // Title theme\\n      settings.setThemeTitleColor(R.color.white);\\n      settings.setThemeTitleStripeColor(R.color.colorPrimary);\\n\\n      // Button theme\\n      settings.setThemeButtonColor(R.color.colorAccent);\\n      settings.setThemeAccentFontColor(R.color.white);\\n      \\n       // Launch the Rewards screen\\n        mojo.launchAvailableRewardsScreen(rewards, settings, ChooserActivity.this);\\n    }\\n\\n    @Override\\n    public void unavailable() {\\n        progressDialog.dismiss();\\n    }\\n  \\n    @Override\\n    public void grabbed(Intent data) {\\n\\n    }\\n\\n    @Override\\n    public void error(String error) {\\n\\n    }  \\n});\\n\\n\",\n      \"language\": \"java\",\n      \"name\": \"Milestones & Rewards\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Checking if rewards are available for your Country\"\n}\n[/block]\nYou can enable / disable certain parts of your app based on whether Codemojo Rewards are available for those regions. You can easily do that like following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// You can check based on Lat/Lon\\ngetCodemojoClient().getRewardsService().isRewardsEnabledForRegion(latitude, longitude, new ResponseAvailable() {\\n                    @Override\\n                    public void available(Object result) {\\n                        boolean isAvailable = (boolean) result;\\n                    }\\n                });           \\n\\n// You can check based on Locale\\ngetCodemojoClient().getRewardsService().isRewardsEnabledForRegion(country_short_code, new ResponseAvailable() {\\n                    @Override\\n                    public void available(Object result) {\\n                        boolean isAvailable = (boolean) result;\\n                    }\\n                });              \\n\\n\\n// Or let the SDK decide with the best possible source available\\ngetCodemojoClient().getRewardsService().isRewardsEnabledForRegion(\\n                  new ResponseAvailable() {\\n                    @Override\\n                    public void available(Object result) {\\n                        boolean isAvailable = (boolean) result;\\n                    }\\n                });\",\n      \"language\": \"java\",\n      \"name\": \"Check for Rewards availability in a Region\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"SDK Hooks & Events\"\n}\n[/block]\nYou can hook into the Rewards flow and by-pass any part of it. There are 3 main hooks\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Hook Name\",\n    \"0-0\": \"ON_REWARD_SELECT\",\n    \"h-1\": \"Intent Action\",\n    \"0-1\": \"codemojo_reward_select\",\n    \"1-0\": \"ON_REWARD_GRAB_CLICK\",\n    \"1-1\": \"codemojo_reward_grab_click\",\n    \"2-0\": \"ON_VIEW_MILESTONE_CLICK\",\n    \"2-1\": \"codemojo_view_milestone_click\",\n    \"3-0\": \"ON_ERROR\",\n    \"3-1\": \"codemojo_error\"\n  },\n  \"cols\": 2,\n  \"rows\": 4\n}\n[/block]\n## Registering for hooks / events\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class ChooserActivity extends AppCompatActivity implements RewardsDialogListener {\\n   \\n    @Override\\n    protected void onCreate(Bundle savedInstanceState) {\\n      super.onCreate(savedInstanceState);\\n      setContentView(R.layout.activity_chooser);\\n  \\n      RewardsScreenSettings settings = new RewardsScreenSettings();\\n      settings.setRewardSelectListener(this);\\n      settings.setTitleClickListener(this);\\n      settings.setViewMilestoneClickListener(this);\\n      settings.setRewardGrabListener(this);\\n      settings.setRewardsErrorListener(this);\\n    }\\n\\n    @Override\\n\\t\\tpublic boolean onClick(Intent data, Context context) {\\n        // Handle stuffs here - return true if you are handling & consuming the event & don't want the SDK to continue the regular flow\\n      if(data.getAction().equals(Codemojo.ON_REWARD_SELECT)){\\n        BrandReward reward = (BrandReward) data.getSerializableExtra(\\\"reward\\\");\\n        ReferralScreenSettings settings = (ReferralScreenSettings) data.getSerializableExtra(\\\"settings\\\");\\n\\n        // Display your UI etc.\\n        \\n        return true;\\n        \\n      }else if(data.getAction().equals(Codemojo.ON_VIEW_MILESTONE_CLICK)){\\n        // If the user has selected a reward before clicking on the View milestone - Check for NULL\\n        BrandReward reward = (BrandReward) data.getSerializableExtra(\\\"reward_details\\\");\\n        \\n        // Display your UI etc.\\n        \\n        return true;\\n\\n      }else if(data.getAction().equals(Codemojo.ON_REWARD_GRAB_CLICK)){\\n        BrandReward reward = (BrandReward) data.getSerializableExtra(\\\"reward_details\\\");\\n\\n        // Display your UI etc.\\n        \\n        return true;\\n      }\\n      return false;\\n    }\\n\\n  \\t@Override\\n    public void onError(String error) {\\n        Toast.makeText(this, \\\"Hook Error: \\\" + error, Toast.LENGTH_SHORT).show();\\n    }\\n\\n}\\n  \",\n      \"language\": \"java\",\n      \"name\": \"Hooks & Events\"\n    }\n  ]\n}\n[/block]\n## Closing the Rewards flow\n\nYou can stop & close the Rewards flow anytime by calling the following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"getCodemojoClient().closeRewardsScreen();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Handling after the Rewards completion\"\n}\n[/block]\nOnce the user completes the Rewards grab / exits from the flow, Codemojo SDK notifies the parent activity of the status.\n\nIf there was a successful reward grab, you will get the reward that was grabbed by the user along with the Preference of communication (email id or phone number). From here you can store it locally for the user to revisit & take it from the app or Open a share sheet.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\nprotected void onActivityResult(int requestCode, int resultCode, Intent data) {\\n    if(requestCode == Codemojo.CODEMOJO_REWARD_USER){\\n\\n      if(resultCode == Activity.RESULT_OK){\\n      \\n          // Get the reward that was grabbed by the user\\n            BrandGrabbedOffer reward = (BrandGrabbedOffer) data.getSerializableExtra(\\\"reward\\\");\\n \\n         // Get the details about the reward\\n\\t\\t        BrandReward reward_details = (BrandReward) data.getSerializableExtra(\\\"reward_details\\\");\\n        \\n        \\n          \\n        // Get the communication channel entered by the user (Email ID/Phone number)\\n            String communication = data.getStringExtra(\\\"communication_channel\\\");\\n          \\n          // Store this in you app / show a share sheet / process\\n            Toast.makeText(this, \\\"Coupon code \\\" + reward.getCouponCode() + \\\" for \\\" + communication, Toast.LENGTH_SHORT).show();\\n        } else {\\n          // Handle failure\\n            if(data != null) {\\n                String error = data.getStringExtra(\\\"error\\\");\\n                if (error != null && !error.isEmpty()) {\\n                    Toast.makeText(this, \\\"Oops! \\\" + error, Toast.LENGTH_SHORT).show();\\n                }\\n            }\\n        }\\n    } else {\\n       // Handle your other results ...\\n        super.onActivityResult(requestCode, resultCode, data);\\n    }\\n}\\n\",\n      \"language\": \"java\",\n      \"name\": \"Handling Activity Result\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Available methods\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Method\",\n    \"h-2\": \"Comments\",\n    \"h-1\": \"Available Parameters\",\n    \"0-0\": \"onRewardsAvailable\",\n    \"1-0\": \"getAvailableRewards\",\n    \"2-0\": \"isRewardsEnabledForRegion\",\n    \"3-0\": \"grabReward\",\n    \"0-1\": \"**String user_communication_id**\\nEmail or Phone number of the end user taking the reward\\n\\n**String countryCode**\\nShort country code\\n\\n**Double latitude, longitude**\\nLatitude & Longitude for rewards\\n\\n**Map<String, String> filters** \\nAdditional filters including **testing, device_id, locale, lat, lon**\",\n    \"1-1\": \"**String user_communication_id**\\nEmail or Phone number of the end user taking the reward\\n\\n**Map<String, String> filters** \\nAdditional filters including **testing, device_id, locale, lat, lon**\",\n    \"2-1\": \"**String country_code** \\nShort country code ex. IN, UK, GB\",\n    \"3-1\": \"**String reward_id**\\nReward id to be redeemed\\n\\n**String communication_channel**\\nEmail or Phone number of the end user taking the reward\\n\\n**Map<String, String> additional_details** \\nAdditional details including ** testing, device_id, locale, lat, lon, age, gender, communicate**\",\n    \"0-2\": \"Triggers an event when rewards are available, ignores otherwise\",\n    \"1-2\": \"Gets you the list of available rewards based on the parameters, null otherwise\",\n    \"2-2\": \"Checks if rewards mojo has been enabled for this region\",\n    \"3-2\": \"Grabs the rewards & optionally sends out communication to the user about the grabbed reward\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Proguard\"\n}\n[/block]\nIf you are using proguard please include the following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"-dontwarn java.nio.**\\n-dontwarn java.lang.**\\n-dontwarn org.codehaus.**\\n\\n-keep class io.codemojo.sdk.models.** { *; }\\n-keep class io.codemojo.sdk.responses.** { *; }\\n\",\n      \"language\": \"yaml\",\n      \"name\": \"Proguard\"\n    }\n  ]\n}\n[/block]","excerpt":"Real time low latency rewards fulfilment system","slug":"rewards-mojo","type":"basic","title":"Rewards Mojo"}

Rewards Mojo

Real time low latency rewards fulfilment system

Rewards fulfilment service provides you with real rewards that can be awarded to your users. This allows you to plan strategic and tactical campaign to engage your users and reward them on reaching milestones [block:api-header] { "type": "basic", "title": "Initialization" } [/block] Add the following to your **AndroidManifest.xml** [block:code] { "codes": [ { "code": "<!-Required to fetch the reward from the Codemojo Servers-->\n<uses-permission android:name=\"android.permission.INTERNET\" />\n\n<!--Required to access the Advertisement ID & Coarse locale of the user-->\n<uses-permission android:name=\"android.permission.READ_PHONE_STATE\" />\n\n<!--Optional-->\n<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />\n\n<application ...>\n ...\n <activity android:name=\"io.codemojo.sdk.ui.AvailableRewardsActivity\" />\n <activity android:name=\"io.codemojo.sdk.ui.RewardDetailsActivity\" />\n ...\n</application>\n", "language": "xml", "name": "AndroidManifest.xml" } ] } [/block] Add the following to your **build.gradle** file or download the SDK from [here](https://github.com/codemojo-dr/startkit-android-sdk) [block:html] { "html": "<a target=\"_blank\" href='https://bintray.com/codemojo/maven/sdk/_latestVersion'><img src='https://api.bintray.com/packages/codemojo/maven/sdk/images/download.svg'></a>" } [/block] [block:code] { "codes": [ { "code": "dependencies {\n compile 'io.codemojo.sdk:sdk:1.0.5+'\n}", "language": "groovy", "name": "build.gradle" } ] } [/block] [block:api-header] { "title": "Your First Reward" } [/block] [block:code] { "codes": [ { "code": "Codemojo mojo = new Codemojo(activity_context, \"your_client_app_token\", \"user_id\", false);\n\nmojo.initRewardsService(\"your_app_id_from_codemojo\");\n\n// Configuration for the UI Screen\nRewardsScreenSettings settings = new RewardsScreenSettings();\n\n// Testing\nsettings.setTesting(true);\n\n// Location India\nsettings.setLocale(\"in\");\n\n// Launch the Rewards screen\nmojo.launchAvailableRewardsScreen(settings, this);\n", "language": "java", "name": "Reward your users" } ] } [/block] [block:api-header] { "type": "basic", "title": "Alternative method for launching the Rewards flow" } [/block] The SDK handles the entire UI required for rewarding the user which is customizable to fit to the look & feel of your App. This includes two screens * Rewards Screen - that shows the available rewards - * Reward Details Screen - that shows the fine print of the reward with a configurable option to Grab the reward from the same screen * Milestones Screen - that allows you to show the milestones associated to unlock the rewards **[Click here for details on Rewards Screen Settings](http://docs.codemojo.io/v1/page/android-rewards-screen-settings)** [block:callout] { "type": "danger", "title": "Testing Environment", "body": "When you are testing the rewards system for your app, it is important to set the Testing parameter to true" } [/block] ## Rewarding the Users Simplest way to show the Rewards screen to the user will be the following way. Codemojo SDK offers you a wrapper thats lets you gracefully handle Rewards availability [block:code] { "codes": [ { "code": "Map<String, String> filters = new HashMap<>();\nfilters.put(\"testing\", \"true\");\nfilters.put(\"locale\", \"in\");\n\nmojo.getRewardsService().onRewardsAvailable(\"\", filters, new RewardsAvailability() {\n\n ProgressDialog progressDialog;\n\n @Override\n public void processing() {\n progressDialog = ProgressDialog.show(ChooserActivity.this, \"\", \"One moment please...\");\n progressDialog.setCancelable(true);\n }\n\n @Override\n public void available(List<BrandReward> rewards) {\n progressDialog.dismiss();\n RewardsScreenSettings settings = new RewardsScreenSettings();\n\n settings.setAllowGrab(true);\n \n // Testing\n settings.setTesting(true);\n \n // Title theme\n settings.setThemeTitleColor(R.color.white);\n settings.setThemeTitleStripeColor(R.color.colorPrimary);\n\n // Button theme\n settings.setThemeButtonColor(R.color.colorAccent);\n settings.setThemeAccentFontColor(R.color.white);\n \n // Launch the Rewards screen\n mojo.launchAvailableRewardsScreen(rewards, settings, ChooserActivity.this);\n }\n\n @Override\n public void unavailable() {\n progressDialog.dismiss();\n }\n \n @Override\n public void grabbed(Intent data) {\n\n }\n\n @Override\n public void error(String error) {\n\n }\n\n});\n", "language": "java", "name": "Rewarding" } ] } [/block] ## Showing available Rewards & Milestones to the users Showing the grab screen is good, but ideally you would want your users to know what they will be getting and when. The SDK allows you to do this with a few modification to the previous process [block:code] { "codes": [ { "code": "Map<String, String> filters = new HashMap<>();\nfilters.put(\"testing\", \"true\");\nfilters.put(\"locale\", \"in\");\n\nmojo.getRewardsService().onRewardsAvailable(null, filters, new RewardsAvailability() {\n ProgressDialog progressDialog;\n\n @Override\n public void processing() {\n progressDialog = ProgressDialog.show(ChooserActivity.this, \"\", \"One moment please...\");\n progressDialog.setCancelable(true);\n }\n\n @Override\n public void available(List<BrandReward> rewards) {\n progressDialog.dismiss();\n RewardsScreenSettings settings = new RewardsScreenSettings();\n\n /*\n * HERE IS WHERE YOU WILL SET IT TO VIEW-ONLY MODE\n */\n settings.setAllowGrab(false);\n \n /*\n * SET THE MILESTONES\n */\n ArrayList<Milestone> milestones = new ArrayList<>();\n milestones.add(new Milestone(0, \"Each 50th time you open the app\"));\n milestones.add(new Milestone(0, \"Every 10th time you post a facebook update\"));\n milestones.add(new Milestone(0, \"Every time you refer it to your contacts\"));\n settings.setMileStones(milestones);\n\n // Testing\n settings.setTesting(true);\n \n // Title theme\n settings.setThemeTitleColor(R.color.white);\n settings.setThemeTitleStripeColor(R.color.colorPrimary);\n\n // Button theme\n settings.setThemeButtonColor(R.color.colorAccent);\n settings.setThemeAccentFontColor(R.color.white);\n \n // Launch the Rewards screen\n mojo.launchAvailableRewardsScreen(rewards, settings, ChooserActivity.this);\n }\n\n @Override\n public void unavailable() {\n progressDialog.dismiss();\n }\n \n @Override\n public void grabbed(Intent data) {\n\n }\n\n @Override\n public void error(String error) {\n\n } \n});\n\n", "language": "java", "name": "Milestones & Rewards" } ] } [/block] [block:api-header] { "type": "basic", "title": "Checking if rewards are available for your Country" } [/block] You can enable / disable certain parts of your app based on whether Codemojo Rewards are available for those regions. You can easily do that like following [block:code] { "codes": [ { "code": "// You can check based on Lat/Lon\ngetCodemojoClient().getRewardsService().isRewardsEnabledForRegion(latitude, longitude, new ResponseAvailable() {\n @Override\n public void available(Object result) {\n boolean isAvailable = (boolean) result;\n }\n }); \n\n// You can check based on Locale\ngetCodemojoClient().getRewardsService().isRewardsEnabledForRegion(country_short_code, new ResponseAvailable() {\n @Override\n public void available(Object result) {\n boolean isAvailable = (boolean) result;\n }\n }); \n\n\n// Or let the SDK decide with the best possible source available\ngetCodemojoClient().getRewardsService().isRewardsEnabledForRegion(\n new ResponseAvailable() {\n @Override\n public void available(Object result) {\n boolean isAvailable = (boolean) result;\n }\n });", "language": "java", "name": "Check for Rewards availability in a Region" } ] } [/block] [block:api-header] { "type": "basic", "title": "SDK Hooks & Events" } [/block] You can hook into the Rewards flow and by-pass any part of it. There are 3 main hooks [block:parameters] { "data": { "h-0": "Hook Name", "0-0": "ON_REWARD_SELECT", "h-1": "Intent Action", "0-1": "codemojo_reward_select", "1-0": "ON_REWARD_GRAB_CLICK", "1-1": "codemojo_reward_grab_click", "2-0": "ON_VIEW_MILESTONE_CLICK", "2-1": "codemojo_view_milestone_click", "3-0": "ON_ERROR", "3-1": "codemojo_error" }, "cols": 2, "rows": 4 } [/block] ## Registering for hooks / events [block:code] { "codes": [ { "code": "public class ChooserActivity extends AppCompatActivity implements RewardsDialogListener {\n \n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_chooser);\n \n RewardsScreenSettings settings = new RewardsScreenSettings();\n settings.setRewardSelectListener(this);\n settings.setTitleClickListener(this);\n settings.setViewMilestoneClickListener(this);\n settings.setRewardGrabListener(this);\n settings.setRewardsErrorListener(this);\n }\n\n @Override\n\t\tpublic boolean onClick(Intent data, Context context) {\n // Handle stuffs here - return true if you are handling & consuming the event & don't want the SDK to continue the regular flow\n if(data.getAction().equals(Codemojo.ON_REWARD_SELECT)){\n BrandReward reward = (BrandReward) data.getSerializableExtra(\"reward\");\n ReferralScreenSettings settings = (ReferralScreenSettings) data.getSerializableExtra(\"settings\");\n\n // Display your UI etc.\n \n return true;\n \n }else if(data.getAction().equals(Codemojo.ON_VIEW_MILESTONE_CLICK)){\n // If the user has selected a reward before clicking on the View milestone - Check for NULL\n BrandReward reward = (BrandReward) data.getSerializableExtra(\"reward_details\");\n \n // Display your UI etc.\n \n return true;\n\n }else if(data.getAction().equals(Codemojo.ON_REWARD_GRAB_CLICK)){\n BrandReward reward = (BrandReward) data.getSerializableExtra(\"reward_details\");\n\n // Display your UI etc.\n \n return true;\n }\n return false;\n }\n\n \t@Override\n public void onError(String error) {\n Toast.makeText(this, \"Hook Error: \" + error, Toast.LENGTH_SHORT).show();\n }\n\n}\n ", "language": "java", "name": "Hooks & Events" } ] } [/block] ## Closing the Rewards flow You can stop & close the Rewards flow anytime by calling the following [block:code] { "codes": [ { "code": "getCodemojoClient().closeRewardsScreen();", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Handling after the Rewards completion" } [/block] Once the user completes the Rewards grab / exits from the flow, Codemojo SDK notifies the parent activity of the status. If there was a successful reward grab, you will get the reward that was grabbed by the user along with the Preference of communication (email id or phone number). From here you can store it locally for the user to revisit & take it from the app or Open a share sheet. [block:code] { "codes": [ { "code": "@Override\nprotected void onActivityResult(int requestCode, int resultCode, Intent data) {\n if(requestCode == Codemojo.CODEMOJO_REWARD_USER){\n\n if(resultCode == Activity.RESULT_OK){\n \n // Get the reward that was grabbed by the user\n BrandGrabbedOffer reward = (BrandGrabbedOffer) data.getSerializableExtra(\"reward\");\n \n // Get the details about the reward\n\t\t BrandReward reward_details = (BrandReward) data.getSerializableExtra(\"reward_details\");\n \n \n \n // Get the communication channel entered by the user (Email ID/Phone number)\n String communication = data.getStringExtra(\"communication_channel\");\n \n // Store this in you app / show a share sheet / process\n Toast.makeText(this, \"Coupon code \" + reward.getCouponCode() + \" for \" + communication, Toast.LENGTH_SHORT).show();\n } else {\n // Handle failure\n if(data != null) {\n String error = data.getStringExtra(\"error\");\n if (error != null && !error.isEmpty()) {\n Toast.makeText(this, \"Oops! \" + error, Toast.LENGTH_SHORT).show();\n }\n }\n }\n } else {\n // Handle your other results ...\n super.onActivityResult(requestCode, resultCode, data);\n }\n}\n", "language": "java", "name": "Handling Activity Result" } ] } [/block] [block:api-header] { "type": "basic", "title": "Available methods" } [/block] [block:parameters] { "data": { "h-0": "Method", "h-2": "Comments", "h-1": "Available Parameters", "0-0": "onRewardsAvailable", "1-0": "getAvailableRewards", "2-0": "isRewardsEnabledForRegion", "3-0": "grabReward", "0-1": "**String user_communication_id**\nEmail or Phone number of the end user taking the reward\n\n**String countryCode**\nShort country code\n\n**Double latitude, longitude**\nLatitude & Longitude for rewards\n\n**Map<String, String> filters** \nAdditional filters including **testing, device_id, locale, lat, lon**", "1-1": "**String user_communication_id**\nEmail or Phone number of the end user taking the reward\n\n**Map<String, String> filters** \nAdditional filters including **testing, device_id, locale, lat, lon**", "2-1": "**String country_code** \nShort country code ex. IN, UK, GB", "3-1": "**String reward_id**\nReward id to be redeemed\n\n**String communication_channel**\nEmail or Phone number of the end user taking the reward\n\n**Map<String, String> additional_details** \nAdditional details including ** testing, device_id, locale, lat, lon, age, gender, communicate**", "0-2": "Triggers an event when rewards are available, ignores otherwise", "1-2": "Gets you the list of available rewards based on the parameters, null otherwise", "2-2": "Checks if rewards mojo has been enabled for this region", "3-2": "Grabs the rewards & optionally sends out communication to the user about the grabbed reward" }, "cols": 3, "rows": 4 } [/block] [block:api-header] { "type": "basic", "title": "Proguard" } [/block] If you are using proguard please include the following [block:code] { "codes": [ { "code": "-dontwarn java.nio.**\n-dontwarn java.lang.**\n-dontwarn org.codehaus.**\n\n-keep class io.codemojo.sdk.models.** { *; }\n-keep class io.codemojo.sdk.responses.** { *; }\n", "language": "yaml", "name": "Proguard" } ] } [/block]