17
|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package com.beem.project.beem; |
|
5 |
|
18
|
6 |
import java.util.List; |
|
7 |
|
17
|
8 |
import org.jivesoftware.smack.XMPPConnection; |
18
|
9 |
import org.jivesoftware.smack.XMPPException; |
|
10 |
|
|
11 |
import com.beem.project.beem.service.IXMPPFacade; |
17
|
12 |
|
|
13 |
import android.app.Notification; |
|
14 |
import android.app.NotificationManager; |
|
15 |
import android.app.PendingIntent; |
|
16 |
import android.app.Service; |
|
17 |
import android.content.Intent; |
|
18 |
import android.content.res.Resources; |
|
19 |
import android.os.IBinder; |
18
|
20 |
import android.os.RemoteException; |
17
|
21 |
import android.widget.TextView; |
|
22 |
import android.widget.Toast; |
|
23 |
|
|
24 |
/** |
|
25 |
* @author darisk |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class BeemService extends Service { |
|
29 |
|
|
30 |
private NotificationManager notificationManager; |
|
31 |
|
|
32 |
private XMPPConnection connection; |
|
33 |
|
18
|
34 |
private IXMPPFacade.Stub bind = new IXMPPFacade.Stub() { |
|
35 |
|
|
36 |
@Override |
|
37 |
public List<String> getContactList() throws RemoteException { |
|
38 |
// TODO Auto-generated method stub |
|
39 |
return null; |
|
40 |
} |
|
41 |
}; |
|
42 |
|
17
|
43 |
/* (non-Javadoc) |
|
44 |
* @see android.app.Service#onBind(android.content.Intent) |
|
45 |
*/ |
|
46 |
@Override |
|
47 |
public IBinder onBind(Intent arg0) { |
|
48 |
// TODO Auto-generated method stub |
|
49 |
return null; |
|
50 |
} |
|
51 |
|
|
52 |
private void showBasicNotification(int stringResource) { |
|
53 |
String text = (String) getText(stringResource); |
|
54 |
Notification notif = new Notification(R.drawable.logo, text, System.currentTimeMillis()); |
|
55 |
notif.defaults = Notification.DEFAULT_ALL; |
|
56 |
notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity(this, 0, new Intent(),0)); |
|
57 |
notificationManager.notify(stringResource, notif); |
|
58 |
Toast toast = Toast.makeText(this, R.string.BeemServiceCreated, Toast.LENGTH_LONG); |
|
59 |
toast.show(); |
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
public void onCreate(){ |
|
64 |
super.onCreate(); |
18
|
65 |
connection = new XMPPConnection("10.224.13.6"); // address du pc host de l'emulateur |
|
66 |
try { |
|
67 |
connection.connect(); |
|
68 |
connection.login("bart", "bart"); |
|
69 |
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); |
|
70 |
showBasicNotification(R.string.BeemServiceCreated); |
|
71 |
} catch (XMPPException e) { |
|
72 |
// TODO Auto-generated catch block |
|
73 |
Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(), Toast.LENGTH_LONG); |
|
74 |
toast.show(); |
|
75 |
e.printStackTrace(); |
|
76 |
} |
|
77 |
|
17
|
78 |
} |
|
79 |
|
|
80 |
public void onDestroy() { |
|
81 |
showBasicNotification(R.string.BeemServiceDestroyed); |
|
82 |
} |
|
83 |
|
|
84 |
} |