为应用创建 android 锁屏 widgets/notification

Creating android Lockscreen widgets/notification for an app

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

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

HI 可以使用 Android 的 RemoteControlClient 部分来完成,因为 ICS 这部分代码是拦截媒体控件。

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

}