gpt4 book ai didi

android - 服务 Intent 必须是明确的 : Intent

转载 作者:IT老高 更新时间:2023-10-28 13:20:33 26 4
gpt4 key购买 nike

我现在有一个应用程序,我通过广播接收器 (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 }

为了使服务被声明为显式并正常启动,我必须进行哪些更改?在其他类似的线程中尝试了一些答案,但尽管我摆脱了该消息,但该服务无法启动。

最佳答案

您在应用中对服务、 Activity 等所做的任何 Intent 都应始终遵循此格式

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");

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

关于android - 服务 Intent 必须是明确的 : Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27842430/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com