我现在有一个应用程序,我在其中通过广播接收器(MyStartupIntentReceiver)调用服务。广播接收器中调用服务的代码是:
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 中,一切正常):
Unable to start receiver com.duk3r.eortologio2.MyStartupIntentReceiver: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.duk3r.eortologio2.MyService }
为了使服务被声明为显式并正常启动,我必须更改什么?在其他类似的线程中尝试了一些答案,但尽管我删除了该消息,但该服务无法启动。
您对应用程序中的服务、活动等做出的任何意图都应始终遵循此格式
Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);
or
Intent bi = new Intent("com.android.vending.billing.InAppBillingService.BIND");
bi.setPackage("com.android.vending");
隐式意图(当前代码中的意图)被视为安全风险
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)