Via : OpenAndroid.in
Tags : #Source_Code, #Tutorial
Orginal Post: BOOT_COMPLETED BroadcastReceiver In Android
BOOT_COMPLETED BroadcastReceiver In Android
Android BootReciever
Many a time We need to perform some task when Device/Mobile finish it's booting process.
For Example giving notification that "SIM has been Changed" etc.
For this we need a Broadcast receiver that should receive "BOOT_COMPLETED" broadcast. We must know that when a device finishes booting Android System sends "BOOT_COMPLTED" broadcast.
Registering the BootReciever in android manifest file
[code lang="xml"]
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
[/code]
and do not forget to add the following permission in manifest .
[xml]<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>[/xml]
this permission is required to listen/reverie the BOOT_COMPLETED action
BootReceiver.java
[java]Public class BootReceiver extends BroadcastReceiver</pre>
<h2><span style="font-size: 13px; font-weight: normal; line-height: 1.5em;"></span></h2>
public void onReceive(Context context, Intent intent)
// Your code to execute when Boot Completd
Toast.makeText(context, "Booting Completed", Toast.LENGTH_LONG).show();
[/java]
The onRecieve() method of BootReceiver will execute when boot completes, so wee need to write the code inside onReceive() method.
Via : OpenAndroid.in
Tags : #Source_Code, #Tutorial
Orginal Post: BOOT_COMPLETED BroadcastReceiver In Android
0 comments:
Post a Comment