編輯:初級開發
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:
That’s it! From here on it should be possible to use the MediaPlaybackService like any other service。
Android的開發插件ADT 0.9.9升級後遇到了一個低級BUG,就是無法自動列出系統的permission權限列表,這裡Android123給出大家如何從SDK查
4、點ok後,將在項目的根目錄下生成一個jocky_build.XML文件,事實上是一個ant build文件。打開這個文件,作適當修改<?XML version
最近正在學習android的相關知識,遇到了很多問題,其中之一就是再往sdcard卡中添加文件時會出現下面類似的問題: &
TextVIEw 部分字體高[功能]TextVIEw是不支持部分字段高亮的 但是我們可以進行擴展[思路]1. 利用LinearLayout 作為 TextVIEw 的