From 8392eee0a7c1a415878ecda9e1c946e0edaad33d Mon Sep 17 00:00:00 2001 From: gumartinm Date: Wed, 7 Mar 2012 08:13:18 +0100 Subject: [PATCH] Trying to launch my service from Test3Activity. I need a notification which will launch the NextActivity. It does not work at the moment. --- Android/Testing/Test3/AndroidManifest.xml | 4 ++++ .../Test3/src/de/android/test3/NextActivity.java | 23 +++++----------------- .../Test3/src/de/android/test3/Test3Activity.java | 8 ++++++-- .../Test3/src/de/android/test3/TestService.java | 21 +++++++++++++------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Android/Testing/Test3/AndroidManifest.xml b/Android/Testing/Test3/AndroidManifest.xml index 2b26999..2ecb907 100644 --- a/Android/Testing/Test3/AndroidManifest.xml +++ b/Android/Testing/Test3/AndroidManifest.xml @@ -64,6 +64,10 @@ + + + + diff --git a/Android/Testing/Test3/src/de/android/test3/NextActivity.java b/Android/Testing/Test3/src/de/android/test3/NextActivity.java index e067aff..ed3e7e4 100644 --- a/Android/Testing/Test3/src/de/android/test3/NextActivity.java +++ b/Android/Testing/Test3/src/de/android/test3/NextActivity.java @@ -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."); } diff --git a/Android/Testing/Test3/src/de/android/test3/Test3Activity.java b/Android/Testing/Test3/src/de/android/test3/Test3Activity.java index 32ca947..87fc810 100644 --- a/Android/Testing/Test3/src/de/android/test3/Test3Activity.java +++ b/Android/Testing/Test3/src/de/android/test3/Test3Activity.java @@ -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); diff --git a/Android/Testing/Test3/src/de/android/test3/TestService.java b/Android/Testing/Test3/src/de/android/test3/TestService.java index 7ede7d9..3de07fc 100644 --- a/Android/Testing/Test3/src/de/android/test3/TestService.java +++ b/Android/Testing/Test3/src/de/android/test3/TestService.java @@ -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. -- 2.1.4