Trying to launch my service from Test3Activity.
authorgumartinm <gu.martinm@gmail.com>
Wed, 7 Mar 2012 07:13:18 +0000 (08:13 +0100)
committergumartinm <gu.martinm@gmail.com>
Wed, 7 Mar 2012 07:13:18 +0000 (08:13 +0100)
I need a notification which will launch the NextActivity.
It does not work at the moment.

Android/Testing/Test3/AndroidManifest.xml
Android/Testing/Test3/src/de/android/test3/NextActivity.java
Android/Testing/Test3/src/de/android/test3/Test3Activity.java
Android/Testing/Test3/src/de/android/test3/TestService.java

index 2b26999..2ecb907 100644 (file)
                <service
                    android:name=".TestService"
                android:process=":testservice" >
+            <intent-filter>
+                <action android:name="android.intent.action.RUN"/>
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
         </service>
                
     </application>
index e067aff..ed3e7e4 100644 (file)
@@ -118,6 +118,11 @@ public class NextActivity extends Activity {
 
         // Register the listener with the Location Manager to receive location updates
         locationManager.requestLocationUpdates(0, 10, criteria, locationListener, null);
+        
+        
+        
+        //mCallbackText = new TextView(this);
+               //this.doBindService();
     }
     
     
@@ -139,25 +144,8 @@ public class NextActivity extends Activity {
                        return;
                }
                
-               
-               mCallbackText = new TextView(this);
-               this.doBindService();
-               
-               
-               
-               
-               
                webServiceConnection = new MobieAdHttpClient(this.myCookie, url, httpClient, this, syncObject);
                this.exec.execute(webServiceConnection);
-               
-               
-               
-               
-               
-               
-               
-               
-               
     }
     
     
@@ -257,7 +245,6 @@ public class NextActivity extends Activity {
         // applications replace our component.
         boolean prueba = bindService(new Intent(NextActivity.this, 
                 TestService.class), mConnection, Context.BIND_AUTO_CREATE);
-        System.out.print(prueba);
         mIsBound = true;
         mCallbackText.setText("Binding.");
     }
index 32ca947..87fc810 100644 (file)
@@ -90,8 +90,12 @@ public class Test3Activity extends Activity {
                                        CookieSyncManager.getInstance().sync();
                                        //Go to the next activity
                                        StrictMode.setThreadPolicy(currentPolicy);
-                                       this.startActivity(new Intent(Intent.ACTION_RUN).
-                                                       setComponent(new ComponentName("de.android.test3", "de.android.test3.NextActivity")));
+//                                     this.startService(new Intent(Test3Activity.this, TestService.class));
+//                                     this.startActivity(new Intent(Intent.ACTION_RUN).
+//                                                     setComponent(new ComponentName("de.android.test3", "de.android.test3.NextActivity")));
+                                       this.startService(new Intent(Intent.ACTION_RUN).
+                                                       setComponent(new ComponentName("de.android.test3", "de.android.test3.TestService")));
+                                       this.finish();
                        } else {
                                Log.e(TAG, "There must be a weird issue with the server because... There is not cookie!!!!");
                                createErrorDialog(R.string.error_dialog_connection_error);
index 7ede7d9..3de07fc 100644 (file)
@@ -3,7 +3,9 @@ package de.android.test3;
 import java.util.ArrayList;
 import android.app.Notification;
 import android.app.NotificationManager;
+import android.app.PendingIntent;
 import android.app.Service;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Handler;
 import android.os.IBinder;
@@ -82,7 +84,7 @@ public class TestService extends Service {
 
     @Override
     public void onCreate() {
-        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
+        mNM = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
 
         // Display a notification about us starting.
         showNotification();
@@ -123,16 +125,21 @@ public class TestService extends Service {
         CharSequence text = getText(R.string.remote_service_started);
 
         // Set the icon, scrolling text and timestamp
-        Notification notification = new Notification(R.drawable.alert_dialog_icon, text,
-                System.currentTimeMillis());
+        Notification notification = new Notification(R.drawable.alert_dialog_icon, text, System.currentTimeMillis());
 
         // The PendingIntent to launch our activity if the user selects this notification
-        //PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
-        //        new Intent(this, Controller.class), 0);
+        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, NextActivity.class), 0);
+
+        Context context = getApplicationContext();
 
         // Set the info for the views that show in the notification panel.
-        //notification.setLatestEventInfo(this, getText(R.string.remote_service_label),
-        //               text, contentIntent);
+        notification.setLatestEventInfo(context, getText(R.string.remote_service_label), text, contentIntent);
+        notification.defaults |= Notification.DEFAULT_VIBRATE;
+        notification.ledARGB = 0xff00ff00;
+        notification.ledOnMS = 300;
+        notification.ledOffMS = 1000;
+        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
+
 
         // Send the notification.
         // We use a string id because it is a unique number.  We use it later to cancel.