1

I set up a simple app. I wan't to hide it from the drawer and I want to add a Boot Receiver to launch a service.

To hide the application, I read that I had to remove this from the manifest

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

But when I remove it, the boot receiver doesn't work anymore.

I added the permission under the manifest tag

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

and my receiver under application

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

And in the receiver code, there is just a Toast

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Boot Received", Toast.LENGTH_SHORT).show();
    }
}

Why couldn't I set the boot receiver AND the hidden app from drawer?

Thanks

4

1 回答 1

6

Android 3.1开始,所有应用程序在安装后都处于“停止”状态。(这与用户从“设置”应用程序强制停止应用程序后应用程序最终处于的状态相同。)

Android 停止状态

当处于“停止”状态时,应用程序不会因任何原因运行,除非手动启动活动。(意味着无论他们注册的事件如何,都不会调用BroadcastReceviersACTION_PACKAGE_INSTALLED等),直到用户手动运行应用程序。)BOOT_COMPLETED

这是谷歌的反恶意软件举措。谷歌提倡用户应该先从启动器启动一个活动,然后该应用程序才能做很多事情。在活动启动之前阻止BOOT_COMPLETED交付是该论点的逻辑结果。

有关此的更多详细信息:http:
//developer.android.com/about/versions/android-3.1.html#launchcontrols
http://commonsware.com/blog/2011/07/05/boot-completed-regression.html
http ://devmaze.wordpress.com/2011/12/05/activating-applications/

于 2013-11-08T10:10:01.847 回答