{"id":19371940,"url":"https://github.com/chatsecure/chatsecure-push-android","last_synced_at":"2025-07-16T03:41:11.586Z","repository":{"id":35632373,"uuid":"39906468","full_name":"ChatSecure/ChatSecure-Push-Android","owner":"ChatSecure","description":"The Android SDK for ChatSecure-Push-Server","archived":false,"fork":false,"pushed_at":"2016-06-16T17:03:13.000Z","size":339,"stargazers_count":16,"open_issues_count":1,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2023-03-23T21:40:06.369Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChatSecure.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-29T17:23:03.000Z","updated_at":"2023-03-23T21:40:06.370Z","dependencies_parsed_at":"2022-09-08T08:51:07.298Z","dependency_job_id":null,"html_url":"https://github.com/ChatSecure/ChatSecure-Push-Android","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChatSecure%2FChatSecure-Push-Android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChatSecure%2FChatSecure-Push-Android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChatSecure%2FChatSecure-Push-Android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChatSecure%2FChatSecure-Push-Android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChatSecure","download_url":"https://codeload.github.com/ChatSecure/ChatSecure-Push-Android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223928431,"owners_count":17226716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T08:20:38.004Z","updated_at":"2024-11-10T08:20:38.545Z","avatar_url":"https://github.com/ChatSecure.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"#PushSecureDemo-Android\n\nThis is a demo [ChatSecure Push Server](https://github.com/ChatSecure/ChatSecure-Push-Server) Android client.\n\n# Requirements \n\nThis Android demo requires a **ChatSecure Push Server** and a **Google Cloud Messaging account**.\n\n1. Clone and setup the [ChatSecure Push Server](https://github.com/ChatSecure/ChatSecure-Push-Server) Django project. You can also test against our demo heroku instance at `https://chatsecure-push.herokuapp.com/api/v1/`.\n\n2. Register a Google Cloud Messaging Application with [Google Developers](https://developers.google.com/mobile/add)\n\n    At the conclusion of the registration process you'll be presented with a `Server API Key` and a `google-services.json` file.\n\n3. Copy the GCM `Server API Key` to `./push/push/local_settings.py` in the ChatSecure Push Server Django project. Copy `google-services.json` to this project's `./example` directory.\n\n## Using the SDK\n\nCurrently, you must include ChatSecure Push as a submodule. Releases will be published as Maven artifacts.\n\n### 1. Get the SDK\n\nAdd this repository as a git submodule:\n\n```\n$ cd your/project/root\n$ git submodule add https://github.com/ChatSecure/ChatSecure-Push-Android.git ./submodules/chatsecure-push/\n```\n\nEdit your project's root `settings.gradle`. This makes the PushSecure submodule's gradle module available to any other gradle modules within your project.\n\n```groovy\ninclude ':myapp', ':submodules:chatsecure-push:sdk'\n```\n\nEdit your application module's `build.gradle`. This informs gradle that your application's gradle module depends on the PushSecure gradle module (submodule). Say that five times fast.\n\n```groovy\n...\ndependencies {\n    compile project(':submodules:chatsecure-push:sdk')\n}\n```\n\n### 2. Create a PushSecureClient\n\nThe API client is designed to operate against any compatible ChatSecure-Push backend.\n\n```java\nPushSecureClient client = new PushSecureClient(\"https://chatsecure-push.herokuapp.com/api/v1/\");\n```\n\n### 3. Authenticate a user account\n\nYou'll need to have an `Account` registered with the API client to perform requests.\nYou can create or login to an existing account with the `authenticateAccount` method.\nYou should generally do this once per app-launch to ensure you have a fresh Account authentication token.\n\n```java\nclient.authenticateAccount(requiredUsername, requiredPassword, optionalEmail,\n                           new RequestCallback\u003cAccount\u003e() {\n                              @Override\n                              public void onSuccess(Account response) {\n                                // Authenticated Account\n                                // Register this account with the api client\n                                // to perform authenticated requests\n                                client.setAccount(response);\n                              }\n\n                              @Override\n                              public void onFailure(Throwable throwable) {\n                                // An error occurred\n                              }\n                           });\n```\n\nIf you have a persisted `Account` object you can set that at any time. This might be useful if you're managing multiple `Account`s from a single device.\n\n```java\nclient.setAccount(account);\n```\n\n### 4. Register a Pushable Device \n\nOn Android, we'll obtain a GCM token and register a GCM device with ChatSecure Push.\n\n```java\n// Retrieve your GCM token as requiredGcmToken\n// See [Google's example](https://github.com/googlesamples/google-services/blob/e06754fc7d0e4bf856c001a82fb630abd1b9492a/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart/RegistrationIntentService.java#L54)\nclient.createDevice(requiredGcmToken, optionalName, optionalDeviceId,\n                            new RequestCallback\u003cDevice\u003e() {\n                              @Override\n                              public void onSuccess(Device response) {\n                                // Registered Device\n                              }\n\n                              @Override\n                              public void onFailure(Throwable throwable) {\n                                // An error occurred\n                              }\n                           });\n```\n\n### 5. Request a Whitelist Token\n\nA Whitelist token gives its bearer push access to your device. It can be revoked at any time (see 5a).\n\n```java\nclient.createToken(requiredDevice, optionalName,\n                    new RequestCallback\u003cPushToken\u003e() {\n                      @Override\n                      public void onSuccess(PushToken response) {\n                        // Created push token. Share this with a pal\n                        // to let them send your device push messages!\n                      }\n\n                      @Override\n                      public void onFailure(Throwable throwable) {\n                        // An error occurred\n                      }\n                   });\n```\n\n### 5a. Revoke a Whitelist token\n\nThis removes its affiliation with your device, and you will no longer receive pushes from uers who \"know you\" by this token. \n\nHolders of the revoked token won't be immediately notified, but they will be told their token \"does not exist\" the next time they try to use it.\n\n```java\nclient.deleteToken(requiredTokenString,\n                    new RequestCallback\u003cVoid\u003e() {\n                      @Override\n                      public void onSuccess(Void response) {\n                        // Revoked push token\n                      }\n\n                      @Override\n                      public void onFailure(Throwable throwable) {\n                        // An error occurred\n                      }\n                   });\n```\n\n### 6. Send a Push Message\n\nPush Message Recipients are always identified by their Whitelist token.\n\n```java\nclient.sendMessage(requiredWhitelistTokenString, optionalData,\n                    new RequestCallback\u003cMessage\u003e() {\n                      @Override\n                      public void onSuccess(Message response) {\n                        // Sent message\n                      }\n\n                      @Override\n                      public void onFailure(Throwable throwable) {\n                        // An error occurred\n                      }\n                    });\n```\n\n### 7. Parse incoming ChatSecure Push GCM Messages\n\nSee [Google's Example](https://github.com/googlesamples/google-services/blob/e06754fc7d0e4bf856c001a82fb630abd1b9492a/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart/MyGcmListenerService.java) for a complete `GcmListenerService` implementation. Below we include the additions necessary to parse ChatSecure Push messages.\n\n```java\n\npublic class MyGcmService extends GcmListenerService {\n\n    PushParser parser = new PushParser();\n\n    @Override\n    public void onMessageReceived(String from, Bundle data) {\n\n        PushMessage push = parser.parseBundle(from, data);\n\n        if (push != null)\n            Log.d(\"GotPush\", \"Received '\" + push.payload + \"' via token: \" + push.token);\n    }\n    ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchatsecure%2Fchatsecure-push-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchatsecure%2Fchatsecure-push-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchatsecure%2Fchatsecure-push-android/lists"}