On a un service qui se lance.
authorDa Risk <darisk972@gmail.com>
Wed, 18 Mar 2009 00:24:00 +0100
changeset 17 afd3a080d318
parent 16 da30cff7f9ce
child 18 1063d4bde1aa
On a un service qui se lance. Il faut maintenant lui faire effectuer une connexion XMPP
AndroidManifest.xml
res/values/strings.xml
src/com/beem/project/beem/Beem.java
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/service/IXMPPFacade.aidl
--- a/AndroidManifest.xml	Tue Mar 17 22:02:07 2009 +0100
+++ b/AndroidManifest.xml	Wed Mar 18 00:24:00 2009 +0100
@@ -11,6 +11,12 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-    <service android:name="BeemService" android:enabled="true" android:permission="android.permission.INTERNET" android:label="Beem Service"></service>
+    <service android:name="BeemService" android:enabled="true" android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE"><intent-filter><action android:name="com.beem.project.beem.BeemService"></action>
+</intent-filter>
+</service>
 </application>
+<permission android:permissionGroup="android.permission-group.NETWORK" android:label="BeemService" android:description="@string/BeemServiceDescription" android:name="com.beem.project.beem.BEEM_SERVICE"></permission>
+<uses-permission android:name="android.permission.INTERNET"></uses-permission>
+<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
+<uses-permission android:name="com.beem.project.beem.BEEM_SERVICE"></uses-permission>
 </manifest> 
--- a/res/values/strings.xml	Tue Mar 17 22:02:07 2009 +0100
+++ b/res/values/strings.xml	Wed Mar 18 00:24:00 2009 +0100
@@ -2,4 +2,7 @@
 <resources>
     <string name="app_name">Beem</string>
 		
+<string name="BeemServiceDescription">Use the Beem Service</string>
+<string name="BeemServiceCreated">BeemService Created</string>
+<string name="BeemServiceDestroyed">BeemService destroyed</string>
 </resources>
--- a/src/com/beem/project/beem/Beem.java	Tue Mar 17 22:02:07 2009 +0100
+++ b/src/com/beem/project/beem/Beem.java	Wed Mar 18 00:24:00 2009 +0100
@@ -1,37 +1,45 @@
 package com.beem.project.beem;
 
 import android.app.Activity;
+import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 import android.widget.EditText;
 
 public class Beem extends Activity {
-<<<<<<< local
     
     /** Called when the activity is first created.
      * @param savedInstanceState toto
      */
-=======
     public static final String jabberSettings = "Beem";
     private SharedPreferences mSettings;
     /** 
      * Called when the activity is first created. */
->>>>>>> other
     @Override
     public void onCreate(Bundle savedInstanceState) {
-<<<<<<< local
-	super.onCreate(savedInstanceState);
-	setContentView(R.layout.main);
-=======
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
-
         mSettings = getSharedPreferences(jabberSettings, MODE_PRIVATE);
         showJID();
->>>>>>> other
+        Button btConnection = (Button) findViewById(R.id.connection);
+        btConnection.setOnClickListener(new OnClickListener() {
+
+	    @Override
+	    public void onClick(View v) {
+		// TODO Auto-generated method stub
+		startService(new Intent(Beem.this,BeemService.class));
+		
+	    }
+  
+            
+            
+        });
     }
     
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/BeemService.java	Wed Mar 18 00:24:00 2009 +0100
@@ -0,0 +1,59 @@
+/**
+ * 
+ */
+package com.beem.project.beem;
+
+import org.jivesoftware.smack.XMPPConnection;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.os.IBinder;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/**
+ * @author darisk
+ *
+ */
+public class BeemService extends Service {
+
+    private NotificationManager notificationManager;
+
+    private XMPPConnection connection;
+    
+    /* (non-Javadoc)
+     * @see android.app.Service#onBind(android.content.Intent)
+     */
+    @Override
+    public IBinder onBind(Intent arg0) {
+	// TODO Auto-generated method stub
+	return null;
+    }
+    
+    private void showBasicNotification(int stringResource) {
+	String text = (String) getText(stringResource);
+	Notification notif = new Notification(R.drawable.logo, text, System.currentTimeMillis());
+	notif.defaults = Notification.DEFAULT_ALL;
+	notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity(this, 0, new Intent(),0));
+	notificationManager.notify(stringResource, notif);
+	Toast toast = Toast.makeText(this, R.string.BeemServiceCreated, Toast.LENGTH_LONG);
+	toast.show();
+	
+    }
+    
+    public void onCreate(){
+	super.onCreate();
+//	connection = new XMPPConnection("10.0.2.2"); // address du pc host de l'emulateur
+	notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+	showBasicNotification(R.string.BeemServiceCreated);
+    }
+    
+    public void onDestroy() {
+	showBasicNotification(R.string.BeemServiceDestroyed); 
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/IXMPPFacade.aidl	Wed Mar 18 00:24:00 2009 +0100
@@ -0,0 +1,11 @@
+package com.beem.project.beem.service;
+
+// import org.jivesoftware.smack.XMPPConnection;
+
+interface IXMPPFacade {
+
+  //  org.jivesoftware.smack.XMPPConnection getXMPPConnection();
+  
+  List<String> getContactList();
+
+}