Hi

Below is my code. Maybe you find something interesting...

manifest file:::
<receiver android:enabled="true"
android:name=".broadcastreceiver.BootCompletedBroadcastReceiver">

            <intent-filter>
                <action
android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

<service android:name=".service.MonitoringService">
            <intent-filter>
                <action
android:name="your.package.name.MonitoringService" />
            </intent-filter>
        </service>

Broadcast reciever:::


@Override
    public void onReceive(Context context, Intent intent) {
            // Start service.
            Intent serviceIntent = new Intent(context,
MonitoringService.class);
            serviceIntent.putExtra(something, something);
            context.startService(serviceIntent);
    }

But remember! If you deploy app on running emulator don't expect to
see your "BootCompletedBroadcastReceiver" in action. First: deploy
your app. Second: close emulator. Third: run emulator with command:
emulator -avd your_emulator_name

On 21 Lip, 10:54, "A N K ! T" <ankit.awasth...@gmail.com> wrote:
> .i write a app but it is not doing anything..code is given below if anybody
> can help.....
>
> *manifest file:::*
>   <application android:icon="@drawable/icon"
> android:label="@string/app_name">
>
>     <receiver android:name="myBR" >
>         <intent-filter>
>         <action
>         android:name="android.intent.action.BOOT_COMPLETED"/>
>         <category android:name="android.intent.category.HOME"/>
>          </intent-filter>
>         </receiver>
> <service android:name="myService">
>
> <action android:name="com.serceatboot.myService"/>
> </service>
> <activity android:name="myactivity"></activity>
> </application>
>     <uses-sdk android:minSdkVersion="4" />
>
> <uses-permission
> android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
>
> *
> Broadcast reciever*:::
>
> public class myBR extends BroadcastReceiver{
>     @Override
>     public void onReceive(Context context, Intent intent) {
>         // TODO Auto-generated method stub
>
>         Intent serviceIntent=new Intent();
>         serviceIntent.setAction("com.serviceatboot.myService");
>          intent.setClass(context,myService.class);
>          context.startService(serviceIntent);
>
>     }
>
> }
>
> *
> and service*:::public class myService extends Service{
>     @Override
>     public IBinder onBind(Intent intent) {
>         // TODO Auto-generated method stub
>         return null;
>     }
>     @Override
>     public void onCreate() {
>         // TODO Auto-generated method stub
>         super.onCreate();
>     Toast.makeText(this, "service created", Toast.LENGTH_SHORT).show();
>     }
>     @Override
>     public void onStart(Intent intent, int startId) {
>         // TODO Auto-generated method stub
>         super.onStart(intent, startId);
>         Toast.makeText(this, "service started", Toast.LENGTH_SHORT).show();
>          }
>   �...@override
> public void onDestroy() {
>     // TODO Auto-generated method stub
>        Toast.makeText(this, "service Destroyed", Toast.LENGTH_SHORT).show();
>        super.onDestroy();
>
>    }
>
> }
>
> *please let me know if am doing anything wrong or missed something...*
> --
> Ankit

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to