android - 为应用程序创建 android 锁屏小部件/通知

标签 android lockscreen

我见过很多应用都这样做。想到 Lux,还有音乐播放器应用程序和其他应用程序。它们会在锁屏上显示一条通知,其中包含您可以与之交互的功能。我读到锁屏小部件已在 5.0+ 上被删除,但我仍然看到这些应用程序创建了这些锁屏功能。

我是 Android 开发的新手,所以我可能对术语感到困惑。在哪里可以找到有关如何创建此类锁屏功能的信息。

最佳答案

您好,可以使用 RemoteControlClient 来完成自 ICS 以来的 Android 的一部分 这部分代码是拦截媒体控件。

@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);
}

关于android - 为应用程序创建 android 锁屏小部件/通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32600078/

相关文章:

java - 以编程方式将锁屏设置为 "None"?

ios - 一个将在锁定屏幕上显示紧急联系人的应用程序

android - 错误 :(33, 13) 无法解析 : com. facebook.android :audience-network-sdk:4. +

android - 服务与 WindowManager 和通知

javascript - url 无法解析数据 json

Android: Edittext- 获取当前行

ios - 如何使用 iOS SDK 在 Google Cast 中添加锁屏控件?

android - 如何从 "extends Application"类创建 Intent ,上下文为空

react-native - react native : How to detect device lock/unlock event?

Android 锁屏 settext 应用程序崩溃