bindService 失败,魅族手机

转载请注明出处,谢谢http://blog.csdn.net/harryweasley/article/details/52993614

注意,此方法现在已经失效。
注意,此方法现在已经失效。
注意,此方法现在已经失效。

最近做了一个aidl的测试demo,在小米手机上和lg手机上都没问题,可以正常启动远程的service,但是在魅族手机上,bindService一直返回false,onServiceConnected也不会被调用。

代码如下所示:

Intent intent=new Intent();
                intent.setAction("com.ryg.sayhi.MyService");
                intent.setPackage("com.example.lgx.myapplication");
                boolean bb=  bindService(intent,serviceConnection, Context
                        .BIND_AUTO_CREATE);
                Log.i("serviceConnection","绑定的返回结果是"+bb);

通过上面的代码,在魅族手机上照样启动不了,我当时个无语啊,心想魅族手机也太坑了吧,最终找到了解决办法,将代码改为下面的代码,就可以在魅族手机启动,同时小米和lg手机也没有问题。

修改后的代码如下所示:

 Intent intent=new Intent();
                intent.setAction("com.ryg.sayhi.MyService");
                ComponentName cn=new ComponentName("com.example.lgx.myapplication","com.example.lgx" +
                        ".myapplication.AIDLServer");
                intent.setComponent(cn);
              boolean bb=  bindService(intent,serviceConnection, Context
                        .BIND_AUTO_CREATE);

要用ComponentName来标识隐性的intent即可。

猜你喜欢

转载自blog.csdn.net/HarryWeasley/article/details/52993614