有些时候我们使用Service的时需要采用隐式意图启动的方式。 但是Android 5.0一出来后,其中有个特性就是 Service Intent must be explicit,也就是说从Lollipop开始,service服务必须采用显式意图方式启动.
Intent intent = new Intent();
intent.setAction("b.aidl.DownLoadService");
bindService(intent, conn, BIND_AUTO_CREATE);
报错:
java.lang.IllegalArgumentException: Service Intent must be explicit
解决办法:
Intent intent = new Intent();
intent.setAction("b.aidl.DownLoadService");
intent.setPackage("lq.cn.twoapp"); //指定启动的是那个应用(lq.cn.twoapp)中的Action(b.aidl.DownLoadService)指向的服务组件
bindService(intent, conn, BIND_AUTO_CREATE);