服务意向一定要明确:意向 [英] Service Intent must be explicit: Intent
问题描述
我有一个应用程序一段时间,现在我在其中通过广播接收器(MyStartupIntentReceiver)调用服务。在code在广播接收器,以便调用服务是:
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);
}
现在的问题是,在安卓5.0棒棒堂我得到以下错误(Android中的previous版本,一切工作正常):
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);
隐性意图(你有什么在你的$ C $目前三)被认为是一个安全隐患
implicit intents (what you have in your code currently) are considered a security risk
这篇关于服务意向一定要明确:意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!