Android Project Call Butler (8)-----Add boot monitoring Service

Source: Internet
Author: User

Now most of the applications will boot from the boot, call the butler is more so, added the boot monitoring service after the boot, even if you do not open the call Butler application, the same can intercept incoming call information.

How to start the activity or service from boot:

Main steps:

1. To have the service or activity to start the boot (this is the boot to start the listenservice of course)

2. Write a broadcastreceiver to capture the action_boot_completed broadcast and start the activity or service we want to activate after capturing.

Bootcompletedreceiver.java

Package Com.example.callmanager;import Android.app.activity;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import Android.content.sharedpreferences;public Class Bootcompletedreceiver extends Broadcastreceiver {sharedpreferences spf; @Overridepublic void OnReceive (Context context , Intent Intent) {if (Intent.getaction (). Equals (intent.action_boot_completed)) {SPF = Context.getsharedpreferences (" Setting ", activity.mode_private); Intent newintent = new Intent ("Com.example.callmanager.ListenService");  Newintent.addflags (intent.flag_activity_new_task);  Note that this tag must be added, otherwise the start will fail  System.out.println ("Start by broadcast"); if (Spf.getboolean ("Isstartlisten", false)) Context.startservice (newintent);}}}       

Here also take out the user's settings information, if the user does not enable monitoring services, the boot does not start monitoring services, more humane.

3. Register our Broadcastreceiver in the Androidmanifest.xml configuration file

<receiver android:name= ". Bootcompletedreceiver "><intent-filter>  <action android:name=" android.intent.action.BOOT_ Completed "/></intent-filter> </receiver>  

4. Add permissions in the Androidmanifest.xml configuration file that allow us to capture the broadcast

     

This enables the start-up of activity or service with the above four steps.

At this point, the call Butler's basic interception function, as well as display interception information, timing interception, monitoring switch, interception mode function has been fully realized, of course, the application can continue to improve, such as, the interception of records to add notification bar, the production of application Start screen, add gesture swipe, add more rich features such as SMS interception.

Attached: Full code download

Android Project Call Butler (8)-----Add boot monitoring Service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.