At a glance your code looks correct.  I use that same approach and it
works fine (this project for example:
http://unlocking-android.googlecode.com/svn/chapter4/trunk/WeatherReporter/src/com/msi/manning/AndroidManifest.xml).

The only difference I see there is that your "receiver" has the
LAUNCHER category, and that may be causing it not to match (or worse
an illegal combination). Try removing that and see if works.  Also,
try posting more info about the error if that's not the problem (the
debug output of logcat).


On Oct 27, 7:05 am, Breno <[EMAIL PROTECTED]> wrote:
> Hi,
>
>     after i read some posts here in forum, i'm able to start my
> program when phone power up. But i need to start a Service, in this
> case, the service is a notification, just for testing. Here is my
> code.
>
> package com.test.StartupTest;
>
> import android.content.BroadcastReceiver;
> import android.content.Context;
> import android.content.Intent;
> import android.widget.Toast;
>
> public class TesteStartup extends BroadcastReceiver {
>
>         @Override
>         public void onReceive(Context context, Intent intent) {
>                 Toast.makeText(context, "Test to see if this
> works",Toast.LENGTH_LONG).show();
>
>                 //Start explicitly a Service that show in Notification bar a 
> message
>                context.startService(new Intent(context,
> NotifyInfoUser.class));
>         }
>
> }
>
> and the  NotifyInfoUser.java:
>
> package com.test.StartupTest;
>
> import com.test.R;
>
> import android.app.Notification;
> import android.app.NotificationManager;
> import android.app.PendingIntent;
> import android.app.Service;
> import android.content.Intent;
> import android.os.IBinder;
>
> public class NotifyInfoUser extends Service{
>
>         private NotificationManager mNM;
>     private static int MOOD_NOTIFICATIONS = R.layout.main;
>
>         @Override
>     public void onCreate() {
>         mNM = (NotificationManager)
> getSystemService(NOTIFICATION_SERVICE);
>     }
>
>           @Override
>         public void onStart(Intent intent, int startId) {
>                 super.onStart(intent, startId);
>                 showNotification(R.drawable.online_connected, "Connected");
>         }
>
>         private void showNotification(int moodId, CharSequence text) {
>
>         // Set the icon, scrolling text and timestamp.
>         // Note that in this example, we pass null for tickerText.  We
> update the icon enough that
>         // it is distracting to show the ticker text every time it
> changes.  We strongly suggest
>         // that you do this as well.  (Think of of the "New hardware
> found" or "Network connection
>         // changed" messages that always pop up)
>         Notification notification = new Notification(moodId, "Client
> Started", System.currentTimeMillis());
>
>         // The PendingIntent to launch our activity if the user
> selects this notification
>        //I guess putting null in Intent(this,null) can be crashing....
>         PendingIntent contentIntent = PendingIntent.getActivity(this,
> 0,
>                 new Intent(this, null), 0);
>
>         // Set the info for the views that show in the notification
> panel.
>         notification.setLatestEventInfo(this, null, text,
> contentIntent);
>
>         // Send the notification.
>         // We use a layout id because it is a unique number.  We use
> it later to cancel.
>         mNM.notify(MOOD_NOTIFICATIONS, notification);
>     }
>
>     @Override
>     public void onDestroy() {
>         // Cancel the persistent notification.
>         mNM.cancel(MOOD_NOTIFICATIONS);
>     }
>
>         @Override
>         public IBinder onBind(Intent intent) {
>                 return null;
>         }
>
> }
>
> and finally my manifest
>
> <?xml version="1.0" encoding="utf-8"?>
> <manifest
>         xmlns:android="http://schemas.android.com/apk/res/android";
>     package="com.test"
>     android:versionCode="1"
>     android:versionName="1.0.0">
>
>         <uses-permission
> android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
>
>     <application android:icon="@drawable/icon" android:label="@string/
> app_name">
>         <receiver android:name=".StartupTest.TesteStartup">
>             <intent-filter>
>                 <action
> android:name="android.intent.action.BOOT_COMPLETED" />
>                                 <category 
> android:name="android.intent.category.LAUNCHER" /
>
>             </intent-filter>
>         </receiver>
>
>         <service android:name=".StartupTest.NotifyInfoUser"/>
>
>     </application>
> </manifest>
>
> When phone power up, the screen with "This app execute a ilegal
> operation, etc" appear. When i comment the startService, the Toast
> appear in screen. So, what is wrong with the context.startService?
> thanks a lot
>
> Breno
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to