gpt4 book ai didi

android - 在 Android 中设置锁屏背景(就像 Spotify 一样)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:12 34 4
gpt4 key购买 nike

我知道这个话题已经讨论过了here , herehere ,而答案似乎是不可能的。

但我最近在我的 Nexus 4 (4.4.2) 中安装了 Spotify,这似乎是可行的。当我在 Spotify 中听一首歌时,锁屏背景随着我正在听的专辑的封面而​​变化(见截图)。

我的理论是:当手机被锁定时,他们 change the phone wallpaper用专辑封面来改变锁屏背景,然后他们在手机解锁时设置回前一个。但这不是他们的做法,因为在 Spotify 的权限列表中没有“android.permission.SET_WALLPAPER”...:(

他们是怎么做到的?一些理论?

Screenshot lock screen Screenshot lock screen

最佳答案

编辑:以下解决方案仅适用于已将自身注册为媒体 Controller 的应用程序,因此不播放音频的应用程序不能/不应使用此机制来更改锁屏壁纸。


可以使用 RemoteControlClient 来完成, 自 ICS 以来的 Android 的一部分。如果您想要一个工作示例,请下载适用于 Android 的 VLC 并查看 org.videolan.vlc.AudioService:

这部分代码是拦截媒体控件。

/**
* Set up the remote control and tell the system we want to be the default receiver for the MEDIA buttons
* @see http://android-developers.blogspot.fr/2010/06/allowing-applications-to-play-nicer.html
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void setUpRemoteControlClient() {
Context context = VLCApplication.getAppContext();
AudioManager audioManager = (AudioManager)context.getSystemService(AUDIO_SERVICE);

if(Util.isICSOrLater()) {
audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);

if (mRemoteControlClient == null) {
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0);

// create and register the remote control client
mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
audioManager.registerRemoteControlClient(mRemoteControlClient);
}

mRemoteControlClient.setTransportControlFlags(
RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
RemoteControlClient.FLAG_KEY_MEDIA_STOP);
} else if (Util.isFroyoOrLater()) {
audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
}
}

这部分是更新艺术作品,以及其他信息:

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
if(!Util.isICSOrLater()) // NOP check
return;

if (mRemoteControlClient != null) {
MetadataEditor editor = mRemoteControlClient.editMetadata(true);
editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentMedia().getAlbum());
editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentMedia().getArtist());
editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, getCurrentMedia().getGenre());
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentMedia().getTitle());
editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentMedia().getLength());
editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, getCover());
editor.apply();
}
}

关于android - 在 Android 中设置锁屏背景(就像 Spotify 一样),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25815729/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com