Lor*_*ic- 1 hidden android broadcastreceiver android-manifest
我设置了一个简单的应用程序.我不想把它隐藏在抽屉里,我想添加一个Boot Receiver来启动服务.
为了隐藏应用程序,我读到我必须从清单中删除它
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
但当我删除它时,启动接收器不再工作.
我在manifest标签下添加了权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Run Code Online (Sandbox Code Playgroud)
我的接收器正在申请中
<receiver android:name="com.example.receiver.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
在接收器代码中,只有一个Toast
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Boot Received", Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能从启动器设置启动接收器和隐藏的应用程序?
谢谢
从Android 3.1开始,所有应用程序在安装时都处于" 停止 "状态.(这与用户从"设置"应用程序强制停止应用程序后应用程序结束的状态相同.)

While in "stopped" state, the application will not run for any reason, except by a manual launch of an activity. (Meaning no BroadcastReceviers(ACTION_PACKAGE_INSTALLED, BOOT_COMPLETED etc.) will be invoked, regardless of the event for which they have registered, until the user runs the app manually.)
This is an anti-malware move by Google. Google has advocated that users should launch an activity from the launcher first, before that application can go do much. Preventing BOOT_COMPLETED from being delivered until the activity is launched is a logical consequence of the that argument.
有关此内容的更多详细信息: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/
| 归档时间: |
|
| 查看次数: |
1366 次 |
| 最近记录: |