Element Wave Android Integration Procedure - Amazon S3

tibburfrogtownΚινητά – Ασύρματες Τεχνολογίες

14 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

80 εμφανίσεις

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Element  Wave
 
Android  Integration  
Proc
e
dure
 
 
 
 
 
 
 
 
 
1.  
 
Adding  Element  Wave  to  your  app
 
Use  the  method  below  to  add  the  Element  Wave  Android  JAR  to  your  
project:
 
1.

Copy  the  .jar  library  into  
(your  project)/libs  folder
.
 
2.

Right  click  on  the  project:
 
-­‐
>  
properties
 
(1)  
 
-­‐
>  
Java  Build  Path
 
(2)  
 
-­‐
>  
Add  JARs
 
(3)  
 
-­‐
>  navigate  to  the  JAR  file  imported  on  step  1  (4)  
 
-­‐
>  click  
OK
 
(5)  
 
-­‐
>  click  
OK
 
(6).
 
 
 
 
 
 
2.  
 
Setting  
Up  Element  Wave
 
Follow  the  steps  below  to  set  up  Element  Wave  for  your  Android  project:
 
2.1  Editing  the  Android  Manifest
 
1.

The  minimum  SDK  version  supported  by  our  framework  is  9.  
(
android:minSdkVersion="9"
)
 
 
 
 
 
 
 
 
 
 
 
 
2.

Add  all  of  the  following  permissions  
which  are  not  already  in  the  manifest  file.  
Permissions  should  be  added  inside  the  “
<manifest>
”  tag  but  outside  any  other  tag:
 
 
<uses
-­‐
permission  android:name  =  "android.permission.INTERNET"  />
 
<uses
-­‐
permission  android:name="android.permission.GET_ACCOUNTS"
 
/>
 
<uses
-­‐
permission  android:name="android.permission.WAKE_LOCK"  />
 
<uses
-­‐
permission  android:name="android.permission.ACCESS_FINE_LOCATION"  />
 
<uses
-­‐
permission  android:name="android.permission.ACCESS_COARSE_LOCATION"  />
 
<uses
-­‐
permission  
android:name="android.permission.VIBRATE"  />
 
<permission  android:name="YOUR.PACKAGE.NAME.permission.C2D_MESSAGE"
 
android:protectionLevel="signature"  />
 
<uses
-­‐
permission  android:name="YOUR.PACKAGE.NAME.permission.C2D_MESSAGE"  />
 
<uses
-­‐
permission  android:nam
e="com.google.android.c2dm.permission.RECEIVE"  />
 
 
 
 
 
3.

Declare  the  following  services  and  broadcast  receivers  between  "
<application>
"  and  

</application>
"  tags:
 
 
<receiver  android:name="com.google.android.gcm.GCMBroadcastReceiverPlus"  
android:permission=
"com.google.android.c2dm.permission.SEND"  >
 
     
 
   
<intent
-­‐
filter>
 
           
 
<action  android:name="com.google.android.c2dm.intent.RECEIVE"  />
 
           
 
<action  android:name="com.google.android.c2dm.intent.REGISTRATION"  />
 
           
 
<category
 
android:name="YOUR.PACKAGE.NAME"  />
 
         
</intent
-­‐
filter>
 
</receiver>
 
<receiver  android:name="com.google.android.gcm.GCMBroadcastReceiverPlus"
 
android:exported="false

 
>
 
   
<intent
-­‐
filter>
 
       
<action  android:name="YOUR.PACKAGE.NAME.TAKE_ACTION"  />
 
   
</int
ent
-­‐
filter>
 
</receiver>
 
 
<service  android:name="ie.elementsoftware.ElementWaveGcmService"  />
 
<service  android:name="ie.elementsoftware.LocationService"  
android:label="@string/app_name"  android:exported="false">
 
       
<intent
-­‐
filter>  
 
<action  android:name="ie
.elementsoftware.LocationService"></action>
 
 
</intent
-­‐
filter>
 
</service>    
 
<service  android:name="ie.elementsoftware.LifecycleService"  
android:label="@string/app_name"  android:exported="false">
 
<intent
-­‐
filter>
 
<action
 
android:name="ie.elementsoftware.LifecycleService"/>
 
</intent
-­‐
filter>
 
</service>
 
 
 
 
 
 
2
.2  Using  the  Element  Wave  class
 
1.

Add  the  following  line  to  each  file  that  references  Element  Wave:
 
 
import  ie.elementsoftware.ElementWave
 
 
2.

Initialise  Element  Wave  class
 
using  your  Google  project  number  (obtained  from  
Google  as  shown  in  the  following  pages)  and  the  user  and  app  id  from  the  Element  
Wave  dashboard  overriding  the  onCreate  function  in  the  first  activity  of  your  project  
as  follows:  
 
 
 
 
Note  1
 
Element  Wave  parameters  are  
Context
,  
Project
 
Number
,  
A
PP
 
KEY
,  
U
SER
 
K
EY
 
You  can  find  your  USER  KEY  and  APP  KEY  by  clickin
g  

View  Details

 
on  the
 
Element  
Wave
 
dashboard  
here

 
 
 
 
 
 
 
 
Note  2
 
To  check  which  is  the  first  activity  in  your  Android  application  check  which  
 
activity  definition  in  the  manifest  file  contains  the  following  line:
 
 
<category  android:name="andro
id.intent.category.LAUNCHER"  />
 
This  is  the  first  activity  called  when  the  app  is  opened  for  the  first  time.  
 
 
3.

In  each  activity  in  your  app  override  the  onResume  and  the  onPause  methods  to  add  
the  functions  
ElementWave.onResume(this)
 
and  
ElementWave.onPause(th
is)
.
 
 
 
 
 
 
 
 
3.
 
User  Tagging
 
To  associate  particular  users  with  specific  groups  or  tags  use  the  
following  syntax:

ElementWave.addTag(“TagName”,  null,  this);
 
 
To  remove  the  association  between  a  particular  user  and  a  tag  use  the  
followi
ng  syntax:
 
ElementWave.removeTag(“TagName”,  this);

Examples:
 
 
 
 
 
 
 
4
.  
 
GCM  Service  and  Google  API
 
4.1  Setting  up  a  Google  API  project
 
Firstly,  you  need  to  create  a  Google  API  project:
 
1.

Open  the
 
Google  APIs  Console  page
.
 
2.

If  you  haven't
 
created  an  API  project  yet,  this  page  will  prompt  you  to  do  so:
 
 
 
Note:
 
If  you  already  have  existing  projects,  the  first  page  you  see  will  be  the  
Dashboard
 
page.  From  there  you  can  create  a  new  project  by  opening  the  project  
drop
-­‐
down  menu  (upper  left  co
rner)  and  choosing  
Other  projects  >  Create
.
 
 
3.

Click
 
Create  project
.  Your  browser  URL  will  change  to  something  like:
 
 
 
https://code.google.com/apis/console/#project:
4815162342
 
 
4.

Take  note  of  the  value  after
 
#project:
 
(4815162342  in  this  example).  This  is  your  
project  number,  and  it  will  be  used  later  on  as  the  GCM  sender  ID.
 
 
 
 
 
4.2  Enablin
g  the  GCM  Service
 
To  enable  the  GCM  service:
 
1.

In  the  main  Google  APIs  Console  page,  select
 
Services
.
 
 
2.

Turn  the
 
Google  Cloud  Messaging
 
toggle  to  ON.
 
 
3.

In  the  Terms  of  Service  page,  accept  the  terms.
 
4.3  Obtaining  an  API  Key
 
To  obtain  an  API  key:
 
1.

In  the  main  
Google  APIs  Console  page,  select
 
API  Access
.  You  will  see  a  screen  that  
resembles  the  following:
 
 
 
2.

Click
 
Create  new  Server  key
.  Either  a  server  key  or  a  browser  key  should  work.  The  
advantage  to  using  a  server  key  is  that  it  allows  you  to  whitelist  IP  
addresses.  The  
following  screen  appears:
 
 
 
 
 
 
3.

Click
 
Create
:
 
 
Note:
 
 
If  you  need  to  rotate  the  key,  click
 
Generate  new  key
.  A  new  key  will  be  created  
while  the  old  one  will  still  be  active  for  up  to  24  hours.  If  you  want  to  get  rid  of  the  old  
key  
immediately  (for  example,  if  you  feel  it  was  compromised),  click
 
Delete  key
.
 
You  are  now  ready  to  send  push  notifications
.