Android Lock Screen and Keyboard Controls

2019-04-15 20:43发布

问题:

I am part way through writing a media player app for Android. It's all going really well so far, however I am now reaching the difficult stage!

I have two questions. Do i need to implement a service activity? As I understand it, this is required to allow the app to continue working in the background. However, mine is working fine while I move to other programs on the tablet, and returns to the app without problems. Can someone please explain what the advantages are of services?

Secondly, I would like to integrate the media player with the standard lock screen controls in ICS, and also make it take advantage of tablets (such as the asus transformer) that have keyboard play/pause skip controls. I would appreciate it if someone could point me in the right direction to get me started. From my googling it would seem that BroadcastReciever is needed, or perhaps RemoteControlClient, but I've no idea where to start!

I have a main activity with actionbar tabs, which contain a music player fragment and soon a video player fragment.

Do i need to create a layout specifically for the lock screen, or can i make use of standard API's?

Any help gratefully received!

回答1:

You should check out the Random Music Player sample that comes with android SDK samples. It gives you lock screen controls and bluetooth control ability on ICS devices & up. I've used it myself, it is excellent. Also, the UniversalMusicPlayer sample on Github: https://github.com/googlesamples/android-UniversalMusicPlayer

Sample code can be found online too.

Igor