I have a small app which runs in background doing some tasks which basically detects the user behavior inside the Android Music application.
I want to check in background if the user pressed the back, play/stop or skip button. It seems like I can a开发者_如何学Goccess information about the current playing song but I have no idea how to put an "observer" to watch those buttons.
Does anyone have an idea to help with?
I am not quite certain why Falmarri chose to use a comment rather than an answer, since his comment is correct: "This isn't possible and would be a huge security hole".
It also assumes the existence of "the Android Music application". There is no single "the Android Music application". There are hundreds, perhaps thousands of "Android Music" apps on the Market. Android devices come with a wide range of pre-installed "Android Music application", based upon whatever the device manufacturer chooses.
You are welcome to:
- write your own "the Android Music application", or
- find an open source "the Android Music application" and contribute to it
UPDATE: To clarify a bit, the "this isn't possible and would be a huge security hole" is for "how to put an 'observer' to watch those buttons". If that were possible, apps could steal passwords and PINs from users.
There is no documented and supported API for the AOSP music player app, and I am unaware of any similar API for any other music player (though some probably have something).
I could solve my problem!
I checked the Android Music App source code and there's a class on com.android.music.MediaPlaybackService wich gives control and you can even switch between activities.
I created a BroadcastReceiver inside a background thread to watch anything from MediaPlaybackService.
精彩评论