Android restrictions on Automatic startup

Source: Internet
Author: User

When talking about how to enable auto-start of a program, I think most of my friends will think that a piece of cake is not just registering a BOOT_COMPLETED message!

Add a receiver in AndroidManifest. xml, as shown in the following figure:

<SPAN style="FONT-SIZE: 18px"><receiver android:name="BootReceiver"><intent-filter><action android:name="android.intent.action.BOOT_COMPLETED"/><action android:name="com.android.settings.MAIL_SENT"/></intent-filter></receiver></SPAN>

However, unfortunately, this is only valid in android 2.3 and earlier versions. In the new android system, this method cannot be automatically started upon startup.


First, take a look at google's official documentation:
 

<SPAN style="FONT-SIZE: 18px">Launch controls on stopped applicationsStarting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state and provides a means of controlling their launch from background processes and other applications.Note that an application's stopped state is not the same as an Activity's stopped state. The system manages those two stopped states separately.The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application.FLAG_INCLUDE_STOPPED_PACKAGES — Include intent filters of stopped applications in the list of potential targets to resolve against.FLAG_EXCLUDE_STOPPED_PACKAGES — Exclude intent filters of stopped applications from the list of potential targets.When neither or both of these flags is defined in an intent, the default behavior is to include filters of stopped applications in the list of potential targets.Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).</SPAN>

The above document mainly describes the following points:

1. There is a type of package in android 3.1 called stopped package, which is the apk that has been installed but never started, or that has been forced to stop in program management.

2. A set of flags (FLAG_INCLUDE_STOPPED_PACKAGES and FLAG_EXCLUDE_STOPPED_PACKAGES) are added to intent. intent with FLAG_INCLUDE_STOPPED_PACKAGES does not work on the stopped package.

3. The system adds flag: FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. Of course, boot complete broadcast is no exception.

After reading these three points, you should know why I mentioned above: Registering static Referer cannot ensure that the app will automatically start when it is started.


The reason is very simple. If my apk has never been started (or stopped by force) after it is installed on my mobile phone, it is a stopped package, boot_complete broadcast cannot be pulled up.

Note that the apk in the/system/app is not a stopped package. So if your mobile phone is root, you can push the apk to system/app. However, this installation method is not normal.


If the apk cannot be automatically started upon startup, you don't have to worry about it. Check out your android version first.

Why should android be added to this mechanism?

It is obvious that for security reasons, because Automatic startup is a common method of virus programs, this mechanism can prevent virus programs from starting automatically.

Related Article

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.