{"action":"created","comment":{"url":"https://api.github.com/repos/google/physical-web/pulls/comments/65427774","id":65427774,"diff_hunk":"@@ -0,0 +1,251 @@\n+/*\n+HereYouGoService.java\n+\n+Shares URLs via bluetooth\n+Also interfaces with PWS to shorten URLs that are too long for Eddystone URLs\n+Lastly, it surfaces a persistent notification whenever a URL is currently being broadcast\n+*/\n+\n+package org.physical_web.physicalweb;\n+\n+\n+import android.annotation.TargetApi;\n+import android.app.NotificationManager;\n+import android.app.PendingIntent;\n+import android.app.Service;\n+import android.bluetooth.BluetoothAdapter;\n+import android.bluetooth.BluetoothManager;\n+import android.bluetooth.le.AdvertiseCallback;\n+import android.bluetooth.le.AdvertiseData;\n+import android.bluetooth.le.AdvertiseSettings;\n+import android.bluetooth.le.BluetoothLeAdvertiser;\n+import android.content.BroadcastReceiver;\n+import android.content.Context;\n+import android.content.Intent;\n+import android.content.IntentFilter;\n+import android.os.Handler;\n+import android.os.IBinder;\n+import android.os.ParcelUuid;\n+import android.support.v4.app.NotificationCompat;\n+import android.support.v4.app.NotificationManagerCompat;\n+import android.support.v4.app.TaskStackBuilder;\n+import android.util.Log;\n+import android.widget.Toast;\n+/**\n+ * Handles url broadcasting.\n+ */\n+@TargetApi(21)\n+public class PhysicalWebBroadcastService extends Service {\n+\n+    private static final String TAG = \"PhysicalWebBroadcastService\";\n+    private BluetoothManager mBluetoothManager;\n+    private BluetoothLeAdvertiser mBluetoothLeAdvertiser;\n+    private static final ParcelUuid URI_BEACON_UUID = ParcelUuid.fromString(\n+        \"0000FEAA-0000-1000-8000-00805F9B34FB\");\n+    private boolean amRunning = false;\n+    private static final int NOTIFICATION_ID = 6;\n+    private NotificationManagerCompat mNotificationManager;\n+    private IBinder mLocalBinder;\n+    private Handler mHandler = new Handler();\n+    private String displayUrl;\n+    private String shareUrl;\n+    private boolean mAmBroadcastingUrl = false;\n+    private static final String SHOULD_BROADCAST_URL_KEY = \"amBroadcastingUrl\";\n+    private static final String LONG_SHARE_URL_KEY = \"longShareUrl\";\n+    private static final String URL_TO_BROADCAST_KEY = \"urlToBroadcast\";\n+    private boolean mCanStopSelf = true;\n+    public int i1;\n+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {\n+\n+        @Override\n+        public void onReceive(Context context, Intent intent) {\n+            Log.d(TAG, \"in receiver\");\n+            String action = intent.getAction();\n+\n+            if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {\n+                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);\n+                switch (state) {\n+                    case BluetoothAdapter.STATE_OFF:\n+                        Log.d(TAG, \"stop becuase BT off\");\n+                        stopSelf();\n+                        break;\n+                }\n+            }\n+        }\n+    };\n+\n+    private void initialize() {\n+        Log.d(TAG, \"SERVICE initialize\");\n+        mBluetoothManager = (BluetoothManager) getApplicationContext().getSystemService(\n+            Context.BLUETOOTH_SERVICE);\n+        mBluetoothLeAdvertiser = mBluetoothManager.getAdapter().getBluetoothLeAdvertiser();\n+        mNotificationManager = NotificationManagerCompat.from(this);\n+    }\n+\n+    /////////////////////////////////\n+    // callbacks\n+    /////////////////////////////////\n+\n+    @Override\n+    public void onCreate() {\n+        super.onCreate();\n+        Log.d(TAG, \"SERVICE onCreate\");\n+        initialize();\n+    }\n+\n+    @Override\n+    public int onStartCommand(Intent intent, int flags, int startId) {\n+        Log.d(TAG, \"SERVICE onStartCommand\");\n+        IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);\n+        registerReceiver(mReceiver, filter);\n+        // Only call initialize once\n+        // We do this because MainActivity launches the service via startService\n+        // but it may call it more than once during initialization\n+        shareUrl = intent.getStringExtra(\"URL\");\n+        displayUrl = intent.getStringExtra(\"OURL\");\n+        Log.d(TAG, shareUrl);\n+        this.broadcastUrl();\n+        Log.d(TAG, \"SERVICE running!\");\n+\n+        // Keep the service running\n+        return START_STICKY;\n+    }\n+\n+    @Override\n+    public void onDestroy() {\n+        Log.d(TAG, \"SERVICE onDestroy\");\n+        unregisterReceiver(mReceiver);\n+        disableUrlBroadcasting();\n+        super.onDestroy();\n+    }\n+\n+    // Fires when user swipes away app from the recent apps list\n+    public void onTaskRemoved (Intent rootIntent) {\n+        Log.d(TAG, \"onTaskRemoved\");\n+        stopSelf();\n+    }\n+\n+    @Override\n+    public IBinder onBind(Intent intent) {\n+        return mLocalBinder;\n+    }\n+\n+    // The callbacks for the ble advertisement events\n+    private final AdvertiseCallback mAdvertiseCallback = new AdvertiseCallback() {\n+\n+        // Fires when the URL is successfully being advertised\n+        @Override\n+        public void onStartSuccess(AdvertiseSettings advertiseSettings) {\n+            Log.d(TAG, \"URL is broadcasting\");\n+            mAmBroadcastingUrl = true;\n+            createNotification();\n+            Toast.makeText(getApplicationContext(), \"URL is broadcasting!\",\n+                Toast.LENGTH_LONG).show();\n+        }\n+\n+        // Fires when the URL could not be advertised\n+        @Override\n+        public void onStartFailure(int result) {\n+            Log.d(TAG, \"onStartFailure\" + result);\n+            mAmBroadcastingUrl = false;\n+        }\n+    };\n+\n+\n+\n+    /////////////////////////////////\n+    // utilities\n+    /////////////////////////////////\n+\n+    // Broadcast via bluetooth the stored URL\n+    private void broadcastUrl() {\n+        //String urlToBroadcast = getUrlToBroadcast();\n+        if (shareUrl != null) {","path":"android/PhysicalWeb/app/src/main/java/org/physical_web/physicalweb/PhysicalWebBroadcastService.java","position":163,"original_position":163,"commit_id":"eb3e7cf6554c3ff7630d65686db3854e4a617af6","original_commit_id":"eb3e7cf6554c3ff7630d65686db3854e4a617af6","user":{"login":"cco3","id":236057,"avatar_url":"https://avatars.githubusercontent.com/u/236057?v=3","gravatar_id":"","url":"https://api.github.com/users/cco3","html_url":"https://github.com/cco3","followers_url":"https://api.github.com/users/cco3/followers","following_url":"https://api.github.com/users/cco3/following{/other_user}","gists_url":"https://api.github.com/users/cco3/gists{/gist_id}","starred_url":"https://api.github.com/users/cco3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cco3/subscriptions","organizations_url":"https://api.github.com/users/cco3/orgs","repos_url":"https://api.github.com/users/cco3/repos","events_url":"https://api.github.com/users/cco3/events{/privacy}","received_events_url":"https://api.github.com/users/cco3/received_events","type":"User","site_admin":false},"body":"We should never call broadcastUrl if shareUrl is null","created_at":"2016-06-01T19:37:47Z","updated_at":"2016-06-01T19:37:47Z","html_url":"https://github.com/google/physical-web/pull/674#discussion_r65427774","pull_request_url":"https://api.github.com/repos/google/physical-web/pulls/674","_links":{"self":{"href":"https://api.github.com/repos/google/physical-web/pulls/comments/65427774"},"html":{"href":"https://github.com/google/physical-web/pull/674#discussion_r65427774"},"pull_request":{"href":"https://api.github.com/repos/google/physical-web/pulls/674"}}},"pull_request":{"url":"https://api.github.com/repos/google/physical-web/pulls/674","id":72090673,"html_url":"https://github.com/google/physical-web/pull/674","diff_url":"https://github.com/google/physical-web/pull/674.diff","patch_url":"https://github.com/google/physical-web/pull/674.patch","issue_url":"https://api.github.com/repos/google/physical-web/issues/674","number":674,"state":"open","locked":false,"title":"Add Share funtionality","user":{"login":"nishadg246","id":10369130,"avatar_url":"https://avatars.githubusercontent.com/u/10369130?v=3","gravatar_id":"","url":"https://api.github.com/users/nishadg246","html_url":"https://github.com/nishadg246","followers_url":"https://api.github.com/users/nishadg246/followers","following_url":"https://api.github.com/users/nishadg246/following{/other_user}","gists_url":"https://api.github.com/users/nishadg246/gists{/gist_id}","starred_url":"https://api.github.com/users/nishadg246/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishadg246/subscriptions","organizations_url":"https://api.github.com/users/nishadg246/orgs","repos_url":"https://api.github.com/users/nishadg246/repos","events_url":"https://api.github.com/users/nishadg246/events{/privacy}","received_events_url":"https://api.github.com/users/nishadg246/received_events","type":"User","site_admin":false},"body":"Allows users to share URLs through the native Android share menu. Doing\r\nso will effectively allow your device, just as Physical Web beacons do,\r\nto broadcast the URL you wish to share.","created_at":"2016-05-31T21:41:50Z","updated_at":"2016-06-01T19:37:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b49bb882db4bda3d2ff1c9cbdd8650c8ac9a5aad","assignee":{"login":"cco3","id":236057,"avatar_url":"https://avatars.githubusercontent.com/u/236057?v=3","gravatar_id":"","url":"https://api.github.com/users/cco3","html_url":"https://github.com/cco3","followers_url":"https://api.github.com/users/cco3/followers","following_url":"https://api.github.com/users/cco3/following{/other_user}","gists_url":"https://api.github.com/users/cco3/gists{/gist_id}","starred_url":"https://api.github.com/users/cco3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cco3/subscriptions","organizations_url":"https://api.github.com/users/cco3/orgs","repos_url":"https://api.github.com/users/cco3/repos","events_url":"https://api.github.com/users/cco3/events{/privacy}","received_events_url":"https://api.github.com/users/cco3/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/google/physical-web/pulls/674/commits","review_comments_url":"https://api.github.com/repos/google/physical-web/pulls/674/comments","review_comment_url":"https://api.github.com/repos/google/physical-web/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/physical-web/issues/674/comments","statuses_url":"https://api.github.com/repos/google/physical-web/statuses/eb3e7cf6554c3ff7630d65686db3854e4a617af6","head":{"label":"nishadg246:share","ref":"share","sha":"eb3e7cf6554c3ff7630d65686db3854e4a617af6","user":{"login":"nishadg246","id":10369130,"avatar_url":"https://avatars.githubusercontent.com/u/10369130?v=3","gravatar_id":"","url":"https://api.github.com/users/nishadg246","html_url":"https://github.com/nishadg246","followers_url":"https://api.github.com/users/nishadg246/followers","following_url":"https://api.github.com/users/nishadg246/following{/other_user}","gists_url":"https://api.github.com/users/nishadg246/gists{/gist_id}","starred_url":"https://api.github.com/users/nishadg246/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishadg246/subscriptions","organizations_url":"https://api.github.com/users/nishadg246/orgs","repos_url":"https://api.github.com/users/nishadg246/repos","events_url":"https://api.github.com/users/nishadg246/events{/privacy}","received_events_url":"https://api.github.com/users/nishadg246/received_events","type":"User","site_admin":false},"repo":{"id":59617356,"name":"physical-web","full_name":"nishadg246/physical-web","owner":{"login":"nishadg246","id":10369130,"avatar_url":"https://avatars.githubusercontent.com/u/10369130?v=3","gravatar_id":"","url":"https://api.github.com/users/nishadg246","html_url":"https://github.com/nishadg246","followers_url":"https://api.github.com/users/nishadg246/followers","following_url":"https://api.github.com/users/nishadg246/following{/other_user}","gists_url":"https://api.github.com/users/nishadg246/gists{/gist_id}","starred_url":"https://api.github.com/users/nishadg246/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishadg246/subscriptions","organizations_url":"https://api.github.com/users/nishadg246/orgs","repos_url":"https://api.github.com/users/nishadg246/repos","events_url":"https://api.github.com/users/nishadg246/events{/privacy}","received_events_url":"https://api.github.com/users/nishadg246/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nishadg246/physical-web","description":"The Physical Web: walk up and use anything","fork":true,"url":"https://api.github.com/repos/nishadg246/physical-web","forks_url":"https://api.github.com/repos/nishadg246/physical-web/forks","keys_url":"https://api.github.com/repos/nishadg246/physical-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nishadg246/physical-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nishadg246/physical-web/teams","hooks_url":"https://api.github.com/repos/nishadg246/physical-web/hooks","issue_events_url":"https://api.github.com/repos/nishadg246/physical-web/issues/events{/number}","events_url":"https://api.github.com/repos/nishadg246/physical-web/events","assignees_url":"https://api.github.com/repos/nishadg246/physical-web/assignees{/user}","branches_url":"https://api.github.com/repos/nishadg246/physical-web/branches{/branch}","tags_url":"https://api.github.com/repos/nishadg246/physical-web/tags","blobs_url":"https://api.github.com/repos/nishadg246/physical-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nishadg246/physical-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nishadg246/physical-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/nishadg246/physical-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nishadg246/physical-web/statuses/{sha}","languages_url":"https://api.github.com/repos/nishadg246/physical-web/languages","stargazers_url":"https://api.github.com/repos/nishadg246/physical-web/stargazers","contributors_url":"https://api.github.com/repos/nishadg246/physical-web/contributors","subscribers_url":"https://api.github.com/repos/nishadg246/physical-web/subscribers","subscription_url":"https://api.github.com/repos/nishadg246/physical-web/subscription","commits_url":"https://api.github.com/repos/nishadg246/physical-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/nishadg246/physical-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/nishadg246/physical-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/nishadg246/physical-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/nishadg246/physical-web/contents/{+path}","compare_url":"https://api.github.com/repos/nishadg246/physical-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nishadg246/physical-web/merges","archive_url":"https://api.github.com/repos/nishadg246/physical-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nishadg246/physical-web/downloads","issues_url":"https://api.github.com/repos/nishadg246/physical-web/issues{/number}","pulls_url":"https://api.github.com/repos/nishadg246/physical-web/pulls{/number}","milestones_url":"https://api.github.com/repos/nishadg246/physical-web/milestones{/number}","notifications_url":"https://api.github.com/repos/nishadg246/physical-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nishadg246/physical-web/labels{/name}","releases_url":"https://api.github.com/repos/nishadg246/physical-web/releases{/id}","deployments_url":"https://api.github.com/repos/nishadg246/physical-web/deployments","created_at":"2016-05-25T00:11:45Z","updated_at":"2016-05-25T00:11:46Z","pushed_at":"2016-06-01T19:06:56Z","git_url":"git://github.com/nishadg246/physical-web.git","ssh_url":"git@github.com:nishadg246/physical-web.git","clone_url":"https://github.com/nishadg246/physical-web.git","svn_url":"https://github.com/nishadg246/physical-web","homepage":"http://physical-web.org","size":12282,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"18868e58eecce9732e0979d8f2cf2a9d832f1899","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":24650339,"name":"physical-web","full_name":"google/physical-web","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/physical-web","description":"The Physical Web: walk up and use anything","fork":false,"url":"https://api.github.com/repos/google/physical-web","forks_url":"https://api.github.com/repos/google/physical-web/forks","keys_url":"https://api.github.com/repos/google/physical-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/physical-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/physical-web/teams","hooks_url":"https://api.github.com/repos/google/physical-web/hooks","issue_events_url":"https://api.github.com/repos/google/physical-web/issues/events{/number}","events_url":"https://api.github.com/repos/google/physical-web/events","assignees_url":"https://api.github.com/repos/google/physical-web/assignees{/user}","branches_url":"https://api.github.com/repos/google/physical-web/branches{/branch}","tags_url":"https://api.github.com/repos/google/physical-web/tags","blobs_url":"https://api.github.com/repos/google/physical-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/physical-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/physical-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/physical-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/physical-web/statuses/{sha}","languages_url":"https://api.github.com/repos/google/physical-web/languages","stargazers_url":"https://api.github.com/repos/google/physical-web/stargazers","contributors_url":"https://api.github.com/repos/google/physical-web/contributors","subscribers_url":"https://api.github.com/repos/google/physical-web/subscribers","subscription_url":"https://api.github.com/repos/google/physical-web/subscription","commits_url":"https://api.github.com/repos/google/physical-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/physical-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/physical-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/physical-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/physical-web/contents/{+path}","compare_url":"https://api.github.com/repos/google/physical-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/physical-web/merges","archive_url":"https://api.github.com/repos/google/physical-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/physical-web/downloads","issues_url":"https://api.github.com/repos/google/physical-web/issues{/number}","pulls_url":"https://api.github.com/repos/google/physical-web/pulls{/number}","milestones_url":"https://api.github.com/repos/google/physical-web/milestones{/number}","notifications_url":"https://api.github.com/repos/google/physical-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/physical-web/labels{/name}","releases_url":"https://api.github.com/repos/google/physical-web/releases{/id}","deployments_url":"https://api.github.com/repos/google/physical-web/deployments","created_at":"2014-09-30T18:32:14Z","updated_at":"2016-06-01T18:12:38Z","pushed_at":"2016-06-01T19:06:56Z","git_url":"git://github.com/google/physical-web.git","ssh_url":"git@github.com:google/physical-web.git","clone_url":"https://github.com/google/physical-web.git","svn_url":"https://github.com/google/physical-web","homepage":"http://physical-web.org","size":12957,"stargazers_count":5390,"watchers_count":5390,"language":"Java","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":651,"mirror_url":null,"open_issues_count":50,"forks":651,"open_issues":50,"watchers":5390,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/physical-web/pulls/674"},"html":{"href":"https://github.com/google/physical-web/pull/674"},"issue":{"href":"https://api.github.com/repos/google/physical-web/issues/674"},"comments":{"href":"https://api.github.com/repos/google/physical-web/issues/674/comments"},"review_comments":{"href":"https://api.github.com/repos/google/physical-web/pulls/674/comments"},"review_comment":{"href":"https://api.github.com/repos/google/physical-web/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/physical-web/pulls/674/commits"},"statuses":{"href":"https://api.github.com/repos/google/physical-web/statuses/eb3e7cf6554c3ff7630d65686db3854e4a617af6"}}}}
{"actor":{"display_login":"cco3"}}