android - java.lang.IllegalArgumentException: Service Intent must be explicit: Intent -


i trying connect android app ms band , getting following error:

java.lang.illegalargumentexception: service intent must explicit: intent { act=com.microsoft.band.service.action.bind_band_service } 

the code snippet using follows:

private view.onclicklistener mbuttonconnectclicklistener = new view.onclicklistener() {     @override     public void onclick(view button) {          pairedbands = bandclientmanager.getinstance().getpairedbands();         bandclient = bandclientmanager.getinstance().create(getapplicationcontext(), pairedbands[0]);          // connect must called on background thread.          new connecttask().execute();         }  };   private class connecttask extends asynctask<bandclient, void, void> {     @override     protected void doinbackground(bandclient... clientparams) {              bandpendingresult<connectionresult> pendingresult = null;         try {             pendingresult = bandclient.connect();         } catch (bandioexception e) {             e.printstacktrace();         }          try {             connectionresult result = pendingresult.await();             if(result == connectionresult.ok) {                  bandconnection.settext("connection worked");              } else {                 bandconnection.settext("connection failed");             }         } catch(interruptedexception ex) {             // handle interruptedexception         } catch(bandexception ex) {             // handle bandexception         }         return null;     }      protected void onpostexecute(void result) {      } } 

i following example given in microsft band sdk, , new this. appreciated.

although @tyczj's comment absolutely true, it's missing workaround. i'll attempt describe problem, origin , (temporary) workaround in answer.

let's identify problem first. somewhere in internals of band sdk call happening:

intent service = new intent("com.microsoft.band.service.action.bind_band_service"); context.bindservice(service, connections, flags); 

an implicit intent created , used bind service. unfortunately, starting android 5.0 no longer allowed bind services uses implicit intents (as described in api changes here). instead, intent should explicit.

since above happening deep inside obfuscated band sdk , don't have sources it, it's not trivial 'update' code use explicit intent. if you're savvy enough, can change java byte code so, i'd propose different workaround:

since exception thrown bindservice() , intent 1 of parameters, can override method ensure whatever intent supplied, ends being explicit.

for example: code below ensures intent action starts com.microsoft.band (which includes, isn't limited com.microsoft.band.service.action.bind_band_service), made explicit setting package name.

contextwrapper bandcontextwrapper = new contextwrapper(getapplicationcontext()) {     @override public boolean bindservice(intent service, serviceconnection conn, int flags) {         final string action = service.getaction();         if (!textutils.isempty(action) && action.startswith("com.microsoft.band")) {             service.setpackage("com.microsoft.band");         }         return super.bindservice(service, conn, flags);     } }; 

you can use wrapper intercept problematic call , update intent (if required) passing bandclientmanager 'context' start service on. so:

bandclient = bandclientmanager.getinstance().create(bandcontextwrapper, pairedbands[0]); 

now should no longer illegalargumentexception. don't have microsoft band myself can't guarantee working after this, should @ least solve problem outlined in question.

do note should considered temporary workaround. pointed out in 1 of comments, microsoft should update sdk comply android 5+. that's proper solution. until then, helps.


Popular posts from this blog