編輯:中級開發
or an Android app I’m working on I need to find out what song, if any, is playing in the background on the device. Turns out there’s no documented way to do this on Android - but it also turns out that using an open source platform is great. After a few hours of poking around I had a working proof of concept, and I’m sure someone more familiar with android would’ve figured it out much faster.
IMPORTANT: I’m using an undocumented interface. While this works on android 1.5R3 and T-Mobile G1 (HTC Magic), and likely on other versions/devices, there is no guarantee it’ll keep working in future releases - use at your own risk.
The default way to play music on the G1 is the Music app. Since it can play music in the background, it seemed likely there is some way to interact with the service it uses. This of course doesn’t help if the user is using some other music player, but it should be good enough.
First step was to figure out exactly what service that is - I used something like the following code to find out what services are running while I’m playing music:
This prints up to 50 running services. The interesting line in the output is
OK, now to figure out how to interact with MediaPlaybackService. It turns out to be surprisingly simple.
First, get a copy of IMediaPlaybackService.aidl from the source code of the Music app, and include it in your android app. The contents of this file are the methods we have Access to in MediaPlaybackService. Of course, if the Music app on the device changes, and our copy of the .aidl file is inaccurate, we have a problem - hence the warning above.
Next, implement a ServiceConnection we can use to connect to MediaPlaybackService.
Finally, bind the service:
簡介: 在這個由五個部分所組成的系列的第一部分中,您將接觸到移動 Web 應用程序中最流行的新技術:地理定位。高端智能手機都內置 GPS,現在您將了解 Web
很多開發者不知道ListVIEw列表控件的快速滾動滑塊是如何啟用的,這裡android開發網告訴大家,輔助滾動滑塊只需要一行代碼就可以搞定,如果你使用XML布局只需要在
對於Android 3.x honeycomb系統來說屏幕的兼容性很重要,這裡目前我們就主流的Android 1.5~2.3.4的軟件如何兼容android 3.0有關
Android ANR這個錯誤大家並不陌生,但是從Android 2.2開始出錯的ANR信息會自動上傳給Google進行系統分析改進,當然了你的應用ANR錯誤其實保存在