I want to mantain a log in my android application , log will contain the Device Started (Bootup) and Device Stop Times. Any Idea how to do this ?
I have to start my appl
You can use BroadcastReceiver component for this purpose. Using this you can detect various events of your device like booting.
To Detect Booting process you need to give permission in AndroidManifest.xml as below,
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
Then you need to create a BrodacastReceiver which will handle this,
In the onReceive() method the corresponding BroadcastReceiver would then start the event,
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, WordService.class);
context.startService(service);
}
}
Use BroadCastReceiver
to receive BOOT_COMPLETED
broadcast. This broadcast is thrown in device startup
The receiver will be like
<receiver
android:name="ReceiverName"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
You will need to use the following persmission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
now in code write a BroadCastReceiver
class like
public class ReceiverName extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// do startup tasks or start your luncher activity
}
}