就在我庆幸这次完成了按字母顺序排列音乐,自定义扫描手机中的音乐两个功能后,准备更新博客,那就发张截图给大家看看我做出来的效果吧!然后发现了BUG。音乐不能播放了!!!事态很严重,立马查找是不是哪的代码被我修改错了,debug一下,流程正常。把报错内容java.lang.IllegalArgumentException: Service Intent must be explicit贴出来查了下原来是前一天我把我手机系统升级到5.0的原因!!
Android 5.0 需要显性调用 Service
于是乎就把Intent修改成显式传递
原来是这么写:
Intent intent = new Intent();
intent.setAction("com.app.media.music_service");
intent.putExtra("idOption", myPosition);
startService(intent);
修改后这么写:
Intent intent = new Intent(MainActivity.this,MusicService.class);
intent.setAction("com.app.media.music_service");
intent.putExtra("idOption", myPosition);
startService(intent);