相关疑难解决方法(0)

服务意图必须是明确的:意图

我现在有一个应用程序,我通过广播接收器(MyStartupIntentReceiver)调用服务.广播接收器中用于呼叫服务的代码是:

public void onReceive(Context context, Intent intent) {
    Intent serviceIntent = new Intent();
    serviceIntent.setAction("com.duk3r.eortologio2.MyService");
    context.startService(serviceIntent);
}
Run Code Online (Sandbox Code Playgroud)

问题是在Android 5.0 Lollipop中我收到以下错误(在以前版本的Android中,一切正常):

Unable to start receiver com.duk3r.eortologio2.MyStartupIntentReceiver: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.duk3r.eortologio2.MyService }
Run Code Online (Sandbox Code Playgroud)

为了将服务声明为显式并正常启动,我需要更改什么?尝试在其他类似的线程中的一些答案,但虽然我摆脱了消息,服务将无法启动.

service android broadcastreceiver

66
推荐指数
3
解决办法
6万
查看次数

标签 统计

android ×1

broadcastreceiver ×1

service ×1