服务意图必须明确:意图 [英] Service Intent must be explicit: Intent

查看:26
本文介绍了服务意图必须明确:意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an app some time now in which I call a service through a broadcast receiver (MyStartupIntentReceiver). The code in the broadcast receiver in order to call the service is:

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

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

The problem is that in Android 5.0 Lollipop I get the following error (in previous versions of Android, everything works ok):

Unable to start receiver com.duk3r.eortologio2.MyStartupIntentReceiver: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.duk3r.eortologio2.MyService }

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

What do I have to change in order for the service to be declared as explicit and start normally? Tried some answers in other similar threads but although i got rid of the message, the service wouldn't start.

推荐答案

您对应用中的服务、活动等做出的任何意图都应始终遵循此格式

any intent you make to a service, activity etc. in your app should always follow this format

Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);

Intent bi = new Intent("com.android.vending.billing.InAppBillingService.BIND");
bi.setPackage("com.android.vending");

隐式意图(您当前在代码中的内容)被视为安全风险

implicit intents (what you have in your code currently) are considered a security risk

这篇关于服务意图必须明确:意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆