Wiki source code of Android

Last modified by editor on 2017/02/08 21:50

Show last authors
1 (% dir="ltr" %)
2 = About =
3
4 (% dir="ltr" %)
5 This page shows how to use the Caret Service Client API in Android application.
6
7 (% dir="ltr" %)
8 The example application can be downloaded from [[https:~~/~~/github.com/pomus/Caret-SampleService>>url:https://github.com/pomus/Caret-SampleService]].
9
10 (% dir="ltr" %)
11 = Android Service Client API usage =
12
13 (% dir="ltr" %)
14 In order to develop your own Caret Service using the API, import the CaretApi and CaretApiConfiguration classes from the com.wallrust.service.sample.util package. Afterwards, perform the following steps:
15
16 == **1. Copy keys** ==
17
18 (% dir="ltr" %)
19 Copy //**Phone Number, Service name, Service Id **//and//** Service Secret Key**// to fields of **CaretApiConfiguration.**
20
21 (% dir="ltr" %)
22 == **2. Init service** ==
23
24 (% dir="ltr" %)
25 Enable Caret integration for your service:
26
27 {{code language="java"}}
28 CaretApi.appInit(new CaretApi.Callback() {
29 @Override
30 public void ok(String UUID) {
31 // save UUID
32 }
33 @Override
34 public void error(String error) {
35 // handle error
36 }
37 });
38 {{/code}}
39
40 == **3. Consent** ==
41
42 (% dir="ltr" %)
43 Ask Caret users for approving your service:
44
45 {{code language="java"}}
46 CaretApi.consent(thisActivity, uuid);
47
48 @Override
49 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
50   if (requestCode == CaretApi.CARET_CONSENT_REQUEST_CODE) {
51       if (resultCode == RESULT_OK) {
52           // consent succes
53       } else {
54           // consent fail
55       }
56   }
57   super.onActivityResult(requestCode, resultCode, data);
58 }
59 {{/code}}
60
61 == **4. Publish user’s status update** ==
62
63 {{code language="java"}}
64 CaretApi.publishStatus(UUID, CaretApi.GAMING);
65 {{/code}}
66
67 or
68
69 {{code language="java"}}
70 CaretApi.publishStatusWithText(UUID, CaretApi.GAMING, "Hello word");
71 {{/code}}
72
73 or
74
75 {{code language="java"}}
76 CaretApi.publishStatusWithContextJSON(UUID, CaretApi.GAMING, json);
77 {{/code}}
78
79 == **5. Publish service-off** ==
80
81 Publish service-off, if the user leaves the application.
82
83 {{code language="java"}}
84 CaretApi.serviceOff(UUID);
85 {{/code}}
86
87 == **6. Delete service** ==
88
89 Delete service consent, if user wants to switch off Caret service.
90
91 {{code language="java"}}
92 CaretApi.appDelete(UUID, new CaretApi.Callback() {
93   @Override
94   public void ok(String result) {
95       // remove UUID
96   }
97
98   @Override
99   public void error(String error) {
100       // handle error
101   }
102 });
103 {{/code}}