{"id":25731181,"url":"https://github.com/zetapush/zetapush-android","last_synced_at":"2026-04-21T16:40:57.861Z","repository":{"id":20765328,"uuid":"90846800","full_name":"zetapush/zetapush-android","owner":"zetapush","description":"Android client for ZetaPush","archived":false,"fork":false,"pushed_at":"2022-04-14T10:05:43.000Z","size":5770,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-13T21:44:50.166Z","etag":null,"topics":["android"],"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/zetapush.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":"2017-05-10T09:32:34.000Z","updated_at":"2023-02-10T21:16:22.000Z","dependencies_parsed_at":"2022-08-07T09:16:16.878Z","dependency_job_id":null,"html_url":"https://github.com/zetapush/zetapush-android","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zetapush/zetapush-android","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetapush%2Fzetapush-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetapush%2Fzetapush-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetapush%2Fzetapush-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetapush%2Fzetapush-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zetapush","download_url":"https://codeload.github.com/zetapush/zetapush-android/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetapush%2Fzetapush-android/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32101085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["android"],"created_at":"2025-02-26T02:37:07.079Z","updated_at":"2026-04-21T16:40:57.825Z","avatar_url":"https://github.com/zetapush.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZetaPush Android library\nThis library manage all the complex connection process for you. You will find utility classes to simplify the processe of connecting to ZetaPush and calling services and macros.\n\n# ZetaPush Android sample\n\nExample of Android project that uses ZetaPush Android SDK\n\n## Install\n\n### Prerequisite\n\nFirst of all, [you have to create an account on ZetaPush](https://doc.zetapush.com/quickstart/)\n\n### Add ZetaPush Android SDK dependency\n\nAdd ZetaPush Nexus repository (`'http://nexus.zpush.io:8080/repository/zetandroid/'`) to your main Gradle file (`build.gradle` at root of your Android project):\n\n![build.gradle](https://user-images.githubusercontent.com/645363/28027104-4d585dca-6598-11e7-97b8-82a9e1c698bf.jpg)\n\n```gradle\n...\nallprojects {\n    repositories {\n        jcenter()\n        maven {\n            url \"http://nexus.zpush.io:8080/repository/zetandroid/\"\n        }\n    }\n}\n...\n```\n\nThen add the ZetaPush Android dependency `'compile com.zetapush:android-library:+'` to the application gradle file (`app/build.gradle`):\n\n![app/build.gradle](https://user-images.githubusercontent.com/645363/28027256-c62b6a6c-6598-11e7-8245-2e0758b5eb23.jpg)\n\n```gradle\n...\n\ndependencies {\n    ...\n    \n    compile 'compile com.zetapush:android-library:+'\n}\n...\n```\n\n\n### Make it work with Android linter\n\nSome dependencies embedded by ZetaPush SDK references classes that are not available in Android.\nThe classes that are using missing classes are never used by ZetaPush SDK. The classes are mainly\nutilities provided by external libraries.\n\nTo disable lint checking, add `lintOptions` section in android configuration (in `app/build.gradle` file):\n\n![app/build.gradle and app/lint.xml](https://user-images.githubusercontent.com/645363/28027103-4d576d66-6598-11e7-8162-9566b205342b.jpg)\n\n```gradle\nandroid {\n    ...\n\n    lintOptions {\n        lintConfig file(\"lint.xml\")\n    }\n}\n```\n\nCreates a file named `lint.xml` in `app` directory with the following content:\n\n```xml\n\u003clint\u003e\n    \u003cissue id=\"InvalidPackage\"\u003e\n        \u003cignore path=\"**/android-client*.jar\"/\u003e\n    \u003c/issue\u003e\n\u003c/lint\u003e\n```\n\n# ZetaPush Android Example\n\n## Usage\n\n### Authentication\n\nTo launch the connection to the ZetaPush platform, we need to have a **ZetaPush Client**. You need to create either a **WeakClient** or a **SmartClient**. The first one provides an anonymous authentication and the second one provides both an anonymous authentication and a simple authentication (we can choose during to connection).\n\n#### WeakClient\n```java\n    WeakClient client = new WeakClient(MainActivity.this);\n    client.connect(SANDBOX_ID);\n    // or client.connect(SANDBOX_ID, DEPLOY_ID);\n    // or client.connect(SANDBOX_ID, DEPLOY_ID, resource);\n```\nThe `SANDBOX_ID` is the ID of your sandbox on the ZetaPush platform. Then, the `DEPLOY_ID` is the id of your authentication service, by default this is *weak_0*. The `resource` is a string to identify your application.\n\n#### SmartClient\n```java\n    SmartClient client = new SmartClient(MainActivity.this);\n    client.connect(SANDBOX_ID);\n    // or client.connect(SANDBOX_ID, DEPLOY_ID);\n    // or client.connect(SANDBOX_ID, LOGIN, PASSWORD);\n    // or client.connect(SANDBOX_ID, LOGIN, PASSWORD, DEPLOY_ID);\n    // or client.connect(SANDBOX_ID, LOGIN, PASSWORD, DEPLOY_ID, resource);\n```\n\nThe variables are the same that the `WeakClient`. The `LOGIN` and the `PASSWORD` are the credentials for the user in his simple authentication. If you put credentials you will connect you as simple authentication, if not, as weak authentication.\n\n\n#### Disconnection\n\n    client.disconnect();\n\n\n#### ConnectionListener\n\nTo get the status connection, you need to create a BroadcastReceiver and listen on the differents events :\n\n\n```java\n    private ZetaPushConnectionReceiver zetaPushReceiver = new ZetaPushConnectionReceiver();\n\n\n    @Override\n    protected void onResume() {\n        super.onResume();\n        registerReceiver(zetaPushReceiver, new IntentFilter(ZetaPushService.FLAG_ACTION_BROADCAST));\n    }\n\n    @Override\n    protected void onPause() {\n        super.onPause();\n        unregisterReceiver(zetaPushReceiver);\n    }\n\n\n    private class ZetaPushConnectionReceiver extends BroadcastReceiver {\n\n        @Override\n        public void onReceive(Context context, Intent intent) {\n\n            switch (intent.getStringExtra(ZetaPushService.FLAG_STATE_CONNECTION)) {\n\n                case ZetaPushService.FLAG_CONNECTION_ESTABLISHED:\n                    Log.e(\"STATE CONNECTION\", \"Connection established\");\n                    break;\n\n                case ZetaPushService.FLAG_CONNECTION_CLOSED:\n                    Log.e(\"STATE CONNECTION\", \"Connection closed\");\n                    break;\n            }\n        }\n    }\n```\n\nFor example, here we only listen on the `ConnectionEstablished` and `ConnectionClosed` events. Here the list of connection events :\n\n*   SuccessfullHandshake\n*   FailedHandshake\n*   ConnectionEstablished\n*   ConnectionBroken\n*   ConnectionClosed\n*   MessageLost\n\n\n### Macroscripts\n\nTo call macroscripts, you need to generate classes from your ZetaPush project. For this, you need to use the command line like this :\n\n    zms sdk -l java -i com.zetapush.monprojet -o /tmp/output_folder\n\n// TODO : Provide the CLI and explain how to install it\n\nThen you put the folder beside the package of your Activity in your Android code. When the classes are imported, you need to use a specific API to call macroscripts :\n\n*   Asynchrone API\n*   Synchrone API\n*   Future API\n\nThe name of your interfaces and classes are specifics to your project but you have an example for each case below. Because we use communication network you need to launch the macroscript calls outside the UI Thread.\n\n\n#### Utils\n\nTo properly understand how to call macroscripts, we need to define some variables. First when we use `\"macro_0\"`, this is the name of the macroscript service in your ZetaPush project. By default this is *macro_0*. The variable `client` is your `WeakClient` or `SmartClient` object.\n\nThen, the macroscript used to make our tests is named `welcome` :\n```java\n    /**\n    * Takes a message as input, and returns it, with a server message\n    */\n    macroscript welcome(/** message from the client */ string message = \"Hello\") {\n        // ...\n    } return {clientMessage : message, serverMessage : WELCOME_MESSAGE}\n```\n\n#### Synchrone API\n\n```java\n    new Thread(new Runnable() {\n        @Override\n        public void run() {\n            try {\n                MacroSyncApi macroApi = MacroSyncApi.Factory.createService(client.getZetaPushClient(), \"macro_0\");\n                welcomeCompletion resultMacro = macroApi.welcome(new welcomeInput(\"test\"));\n                Log.e(\"RESULT MACRO\", resultMacro.getResult().toString());\n            }\n        }\n    }).start();\n```\n\n#### Asynchrone API\n\nIn this case, you need to create a listener that implements the AsyncApiListener.\n\n```java\n    private class MacroApiListener implements MacroAsyncApiListener {\n\n        @Override\n        public void welcome(welcomeCompletion notification) {\n            Log.e(\"RESULT WELCOME\", notification.getResult().toString());\n        }\n    }\n```\n\nThen we can call our macroscripts :\n\n```java\n    new Thread(new Runnable() {\n        @Override\n        public void run() {\n            try {\n                MacroAsyncApi macroApi = MacroAsyncApi.Factory.createService(client.getZetaPushClient(), \"macro_0\");\n                MacroAsyncApiListener.Factory.registerListener(new MacroApiListener(), client.getZetaPushClient(), \"macro_0\");\n                macroApi.welcome(new welcomeInput(\"test\"));\n            }\n        }\n    }).start();\n```\n\n#### Future API\n```java\n    private Future\u003cwelcomeCompletion\u003e resultMacro;\n\n\n    ...\n\n\n    new Thread(new Runnable() {\n        @Override\n        public void run() {\n            try {\n                MacroFutureApi macroApi = MacroFutureApi.Factory.createService(client.getZetaPushClient(), \"macro_0\");\n                resultMacro = macroApiFuture.welcome(new welcomeInput(\"test\"));\n            }\n        }\n    }).start();\n\n\n    ...\n\n\n    try {\n        welcomeCompletion output = resultMacro.get();\n        Log.e(\"RESULT MACRO\", output.getResult().toString());\n    } catch (Exception e) {\n        e.printStackTrace();\n    }\n```\n\n### Storage\n\nFor example if you don't want to save any data, you can use the `NoTokenStorage` and `NoCredentialsStorage` classes that implement the needed interfaces :\n```java\n    SmartClient client = new SmartClient(MainActivity.this, new NoTokenStorage(), new NoCredentialsStorage());\n```\nOf course you also can choose to implements yourself the methods to save, get and delete data. For example if you want to change the method to handle token :\n\n```java\n    SmartClient client = new SmartClient(MainActivity.this, new StorageTokenInterface() {\n        @Override\n        public void saveToken(String token) {\n\n        }\n\n        @Override\n        public String getToken() {\n            return null;\n        }\n\n        @Override\n        public void clearToken() {\n\n        }\n    });\n```\n\n### Secondary methods\n\n\nThe clients implements many other explicit methods. We list them :\n\n#### Client (superclass of WeakClient and SmartClient)\n\n*   getUserKey()\n*   isConnected()\n*   canDoConnection()\n*   getSandboxId()\n*   getResource()\n*   setResource()\n\n#### SmartClient\n\n*   getCredentials()\n*   hasCredentials()\n*   isStronglyAuthenticated()\n*   isWeaklyAuthenticated()\n\n\n#### WeakClient\n\n*   getToken()\n\n\n\n### Basic example\n\nHere is a basic example with a button to launch the connection and another to call a macroscript. We use in our case the asynchrone API and a SmartClient.\n\n```java\n    public class MainActivity extends Activity {\n\n        private Button                          btnConnection;\n        private Button                          btnMacro;\n        private Thread                          threadMacro;\n\n\n        // ZetaPush variables\n        private SmartClient                     client;\n        private ZetaPushConnectionReceiver      zetaPushReceiver = new ZetaPushConnectionReceiver();\n        private final String                    SANDBOX_ID       = \"nL_L8ZqL\";\n        private final String                    LOGIN            = \"user\";\n        private final String                    PASSWORD         = \"password\";\n\n\n\n        @Override\n        protected void onCreate(Bundle savedInstanceState) {\n            super.onCreate(savedInstanceState);\n            setContentView(R.layout.activity_main);\n\n            // Create the ZetaPush Client\n            client = new SmartClient(MainActivity.this);\n\n            // UI\n            btnConnection = (Button) findViewById(R.id.btnConnection);\n            btnMacro = (Button) findViewById(R.id.btnMacro);\n\n            // buttons\n            btnConnection.setOnClickListener(new View.OnClickListener() {\n                @Override\n                public void onClick(View v) {\n                    // Launch the connection to the ZetaPush platform\n                    client.connect(SANDBOX_ID, LOGIN, PASSWORD);\n                }\n            });\n\n            btnMacro.setOnClickListener(new View.OnClickListener() {\n                @Override\n                public void onClick(View v) {\n\n                    // ZetaPush code to call macroscript (Asynchrone)\n                    threadMacro = new Thread(new Runnable() {\n                        @Override\n                        public void run() {\n                            MacroAsyncApi macroApi = MacroAsyncApi.Factory.createService(client.getZetaPushClient(), \"macro_0\");\n                            MacroAsyncApiListener.Factory.registerListener(new MacroApiListener(), client.getZetaPushClient(), \"macro_0\");\n                            macroApi.welcome(new welcomeInput(\"test\"));\n                        }\n                    });\n                    threadMacro.start();\n                }\n            });\n        }\n\n        @Override\n        protected void onResume() {\n            super.onResume();\n            registerReceiver(zetaPushReceiver, new IntentFilter(ZetaPushService.FLAG_ACTION_BROADCAST));\n        }\n\n        @Override\n        protected void onPause() {\n            super.onPause();\n            unregisterReceiver(zetaPushReceiver);\n        }\n\n        @Override\n        protected void onDestroy() {\n            client.disconnect();\n            try {\n                threadMacro.join();\n            } catch (InterruptedException e) {\n                e.printStackTrace();\n            }\n            super.onDestroy();\n        }\n\n        // BroadcastReceiver for the connection status of ZetaPush\n        private class ZetaPushConnectionReceiver extends BroadcastReceiver {\n\n            @Override\n            public void onReceive(Context context, Intent intent) {\n\n                switch (intent.getStringExtra(ZetaPushService.FLAG_STATE_CONNECTION)) {\n\n                    case ZetaPushService.FLAG_CONNECTION_ESTABLISHED:\n                        Log.e(\"STATE CONNECTION\", \"Connection established\");\n                        break;\n\n                    case ZetaPushService.FLAG_CONNECTION_CLOSED:\n                        Log.e(\"STATE CONNECTION\", \"Connection closed\");\n                        break;\n                }\n            }\n        }\n\n        private class MacroApiListener implements AndroidpreprodAsyncApiListener {\n\n            @Override\n            public void welcome(welcomeCompletion notification) {\n                Log.e(\"RESULT MACRO\", notification.getResult().toString());\n            }\n        }\n    }\n```\n\n### How to share ZetaPush service between Activities\n\nWe have created an utility class call ZetaPushBaseActivity than you can use to help you share the ZetaPush service between your activities. If you have your main activity that create the WeakClient or SmarClient object, you can share the ZetaPushService by simply overiding onServiceAttached and onServiceDetached event.\n\nIf you have to create an API listener for your activity, don't forget to use a thread to instantiate it.\n\n\n```java\npublic class ChildActivity extends ZetaPushBaseActivity implements ZetaPushConnectionEvent {\n\n    private ZetapushClient zetapushClient;\n    private String userId;\n    private static final String TAG = ChildActivity.class.getSimpleName();\n\n    @Override\n    protected void onServiceAttached(ZetaPushService service) {\n        // do something necessary by its subclass.\n        Log.d(TAG, \"onServiceAttached\");\n        zetapushClient = service.getZetaPushClient();\n        //userId = zetapushClient.getUserId();\n\n        new Thread() {\n            public void run() {\n                try {\n                    // Create here your futureAPI or API Listeners ?\n                    //futureApi = VisioFutureApi.Factory.createService(zetapushClient, \"macro_0\");\n                    //VisioAsyncApiListener.Factory.registerListener(ZetapushConnectActivity.this, zetapushClient, \"macro_0\");\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n            }\n        }.start();\n\n    }\n\n    @Override\n    protected void onServiceDetached() {\n        Log.d(TAG, \"onServiceDetached\");\n        new Thread() {\n            public void run() {\n                try {\n                    // Unregister your API Listeners\n                    //VisioAsyncApiListener.Factory.unregisterListener(ZetapushConnectActivity.this, zetapushClient);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n            }\n        }.start();\n    }\n\n    @Override\n    public void successfulHandshake(Map\u003cString, Object\u003e map) {\n        Log.d(TAG, \"successfulHandshake\");\n    }\n\n    @Override\n    public void failedHandshake(Map\u003cString, Object\u003e map) {\n        Log.d(TAG, \"failedHandshake\");\n    }\n\n    @Override\n    public void connectionEstablished() {\n        Log.d(TAG, \"connectionEstablished\");\n    }\n\n    @Override\n    public void connectionBroken() {\n        Log.d(TAG, \"connectionBroken\");\n    }\n\n    @Override\n    public void connectionClosed() {\n        Log.d(TAG, \"connectionClosed\");\n    }\n\n    @Override\n    public void messageLost(String s, Object o) {\n\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzetapush%2Fzetapush-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzetapush%2Fzetapush-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzetapush%2Fzetapush-android/lists"}