【发布时间】:2013-09-21 10:44:11
【问题描述】:
我的应用程序使用了一个由 BOOT_COMPLETE BroadcastReceiver 启动的服务,在运行中我遇到了一个错误
我的代码:
public class projet extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
intent = new Intent(context, ScreenshotService.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.bindService(intent, aslServiceConn, Context.BIND_AUTO_CREATE);
}
}
错误:
java.lang.RuntimeException: Unable to start receiver com.example.projet: android.content.ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to bind to services
【问题讨论】:
-
很简单。我创建了一个空 Activity(非 UI,仅用于 Bind 服务的 onCreate())和 finish()。在 Broadcast > Start Activity with Bundle 中(如果需要)。问题已解决。
标签: android