关于Service Intent must be explicit

  今天把Andorid.mk项目迁移为Gradle项目,运行时绑定蓝牙服务报错 Service Intent must be explicit: Intent { act=com.anwsdk.service.AnwPhoneLink }

framework源码:

    private void validateServiceIntent(Intent service) {
if (service.getComponent() == null && service.getPackage() == null) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
IllegalArgumentException ex = new IllegalArgumentException(
"Service Intent must be explicit: " + service);
throw ex;
} else {
// Log.w(TAG, "Implicit intents with startService are not safe: " + service
// + " " + Debug.getCallers(2, 3));
}
}
}


由于我只设置了action,所以会判断App的targetSdkVersion和Build.VERSION_CODES.LOLLPOP(21),由于我targetSdkVersion设置高了,所以报了错误。
改成setComponent方式就可以正常绑定服务了
posted @ 2021-04-02 17:15  我热爱的  阅读(138)  评论(0)    收藏  举报