{"id":1203,"date":"2013-04-09T23:49:52","date_gmt":"2013-04-09T23:49:52","guid":{"rendered":"http:\/\/gusclass.com\/blog\/?p=1203"},"modified":"2015-06-19T23:37:19","modified_gmt":"2015-06-19T23:37:19","slug":"targeting-interactive-post-recipients-in-android","status":"publish","type":"post","link":"http:\/\/gusclass.com\/blog\/2013\/04\/09\/targeting-interactive-post-recipients-in-android\/","title":{"rendered":"Targeting Interactive Post recipients in Android"},"content":{"rendered":"<p>In the\u00a0<a href=\"https:\/\/www.youtube.com\/watch?feature=player_embedded&amp;v=6a6ZdLR99Kg\">April 9th, 2013 Google+ Developers Live<\/a>, Chirag and I demonstrated how to set the recipients for an Interactive Post in Android. \u00a0You can watch the video below:<\/p>\n<p>\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"http:\/\/www.youtube.com\/embed\/6a6ZdLR99Kg\" frameborder=\"0\" allowfullscreen><\/iframe>\n<\/p>\n<p>&nbsp;<\/p>\n<h2>Code from the show<\/h2>\n<p>I have added\u00a0<a href=\"https:\/\/gist.github.com\/gguuss\/5349902\">a gist to GitHub for the code showing how I targeted Android interactive shares<\/a>\u00a0by combining the listPeopleActivity into the ShareActivity. The following snippets cover the relevant code changes relative to the\u00a0<a href=\"https:\/\/developers.google.com\/+\/quickstart\/android\">Android quickstart sample<\/a>:<\/p>\n<p>Adding the PlusClient.OnPeopleLoadedListenter interface, for the asynchronous method from loadPeople:<\/p>\n<pre>public class ShareActivity extends FragmentActivity implements View.OnClickListener,\r\n        OnSignedInListener,\r\n        PlusClient.OnPeopleLoadedListener\r\n        {<\/pre>\n<p>A few variables for holding the PlusClient, used for getting the Interactive Share intent, and the ArrayList of people, populated in the onPeopleLoaded callback.<\/p>\n<pre>    \/\/ Add lists for holding the people from people.list\r\n    private ArrayList&lt;Person&gt; mBestRecipients;\r\n    private PlusClient mPlusClient;<\/pre>\n<p>The onPeopleLoaded asynchronous callback implementation:<\/p>\n<pre>    \/\/ The onPeopleLoaded method for the callback handling the response when the visible\r\n    \/\/ people are listed\r\n    @Override\r\n    public void onPeopleLoaded(ConnectionResult status, PersonBuffer personBuffer,\r\n            String nextPageToken) {\r\n        if (status.getErrorCode() == ConnectionResult.SUCCESS) {\r\n        \tmBestRecipients.clear();\r\n            try {\r\n                int count = personBuffer.getCount();\r\n                for (int i = 0; i &lt; count; i++) {\r\n                \tPerson toAdd = personBuffer.get(i).freeze();\r\n                \tmBestRecipients.add(toAdd);\r\n                }\r\n            } finally {\r\n                personBuffer.close();\r\n            }\r\n        } else {\r\n            Log.e(TAG, &quot;Error when listing people: &quot; + status);\r\n        }\r\n\r\n        Intent intent = getInteractivePostIntent(mPlusClient);  \r\n        startActivityForResult(intent, REQUEST_CODE_INTERACTIVE_POST);\r\n    }<\/pre>\n<p>The code for adding the recipients to the post:<\/p>\n<pre>        \t\r\n        if (best){\r\n        \t\/\/ Use the recipients list created from people.list...best\r\n        \tbuilder.setRecipients(mBestRecipients);\r\n        }<\/pre>\n<h2>Additional Notes, Errata<\/h2>\n<p>There were a few topics that we would have liked to cover in the episode but just didn&#8217;t have enough time for, ended up getting glossed over, or might have been lost when we had recorded live.<\/p>\n<p>While I was setting up the APIs console, I mentioned putting in a meaningful name for the project name. \u00a0What I should have indicated was to use an appropriate brand name for your company and an appropriate name for this particular client ID. \u00a0When you are setting up the project, you want to make sure to get this right because it can be difficult to change it later on.<\/p>\n<p>I really would have liked to show adding specific users by name. \u00a0For example, I was missing Chirag from my list of &#8220;BEST&#8221; people to share with. \u00a0If in code, I wanted to make sure that Chirag was always added as a recipient, I would add him by id using the createPerson method from the platform:<\/p>\n<pre>        \/\/ Create an interactive post builder.\r\n        PlusShare.Builder builder = new PlusShare.Builder(this, plusClient);       \r\n\r\n        builder.addCallToAction(LABEL_VIEW_ITEM, callToActionUrl, callToActionDeepLinkId)\r\n        \t.setContentUrl(Uri.parse(getString(R.string.plus_example_deep_link_url)))\r\n        \t.setContentDeepLinkId(getString(R.string.plus_example_deep_link_id),\r\n                null, null, null)            \r\n            .setText(mEditSendText.getText().toString());     \t\r\n\r\n        if (best){\r\n        \t\/\/ Use the recipients list created from people.list...best\r\n&lt;strong&gt;        \tmBestRecipients.add(PlusShare.createPerson(&quot;118051310819094153327&quot;,&quot;Chirag Shah&quot;));&lt;\/strong&gt;\r\n        \tbuilder.setRecipients(mBestRecipients);\r\n        }<\/pre>\n<p>In the above code snippet, you can see how I have created the recipient,\u00a0<a href=\"https:\/\/plus.google.com\/+chirags\">Chirag Shah<\/a>\u00a0in this case, without using the list of people and instead directly adding by ID and display name. \u00a0In practice, this is a more common use case and would probably be done using your own database of users.<\/p>\n<p>Speaking of, I also would have liked to have had a longer discussion on who to target posts to. \u00a0For example, you could look at\u00a0<a href=\"https:\/\/developers.google.com\/+\/photohunt\/\">the PhotoHunt app that we ship as part of the Google+ platform documentation<\/a>. \u00a0In this sample, we\u00a0<a href=\"http:\/\/gusclass.com\/blog\/2013\/03\/15\/photohunt-an-example-of-social-graph-integration\/\">create an internal social graph of users within the app<\/a>\u00a0to people they know on Google+ who have installed the app. For that app, we could target interactive posts to the people who the current user has in their Circles on Google+ and who have already installed the app.<\/p>\n<p>Another note on the code I showed on the gist, the best practice for Android would be to pre-load the list of people when the activity loads as opposed to waiting until the user clicks. \u00a0That way, the UI doesn&#8217;t lag in cases where there is no internet connectivity. Because I wanted to show the before and after code and lazily copied the code from the ListPeopleActivity, I didn&#8217;t end up doing this.<\/p>\n<p><a href=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/notifications1.png\"><img loading=\"lazy\" alt=\"notifications\" src=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/notifications1.png\" width=\"500\" height=\"101\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/Screenshot_2013-04-11-11-08-491.png\"><a href=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/Screenshot_2013-04-11-11-08-491.png\">\u00a0<\/a><\/a><\/p>\n<p><a href=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/Screenshot_2013-04-11-11-08-491.png\"><img loading=\"lazy\" alt=\"Screenshot_2013-04-11-11-08-49\" src=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/Screenshot_2013-04-11-11-08-49-168x3001.png\" width=\"168\" height=\"300\" \/><\/a><\/p>\n<p>A HUGE point that we didn&#8217;t cover was how the targeted posts appear across all platforms. \u00a0When you specify a specific person, they will get notifications across all of the places that the notifications appear:<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\">Search<\/span><\/li>\n<li>GMail<\/li>\n<li>Google+<\/li>\n<li>Mobile<\/li>\n<li>and so on<\/li>\n<\/ul>\n<p>As such, these targeted interactive posts are much more effective at reaching the people listed in the post.<\/p>\n<p>Hope you enjoyed the GDL, it was fun to demo! Here&#8217;s a snapshot of Chirag and me during the session:<\/p>\n<p><a href=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-09-at-4.52.11-PM1.png\"><img loading=\"lazy\" class=\"alignleft size-medium wp-image-1211\" alt=\"Screen Shot 2013-04-09 at 4.52.11 PM\" src=\"http:\/\/gusclass.com\/blog\/wp-content\/uploads\/2013\/04\/Screen-Shot-2013-04-09-at-4.52.11-PM-300x1691.png\" width=\"300\" height=\"169\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the\u00a0April 9th, 2013 Google+ Developers Live, Chirag and I demonstrated how to set the recipients for an Interactive Post in Android. \u00a0You can watch the video below: &nbsp; Code from the show I have added\u00a0a gist to GitHub for&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[134,91,114,12,135,97,16],"tags":[294,42,295,279],"amp_validity":null,"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/posts\/1203"}],"collection":[{"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/comments?post=1203"}],"version-history":[{"count":9,"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/posts\/1203\/revisions"}],"predecessor-version":[{"id":1798,"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/posts\/1203\/revisions\/1798"}],"wp:attachment":[{"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/media?parent=1203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/categories?post=1203"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gusclass.com\/blog\/wp-json\/wp\/v2\/tags?post=1203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}