我已经通过了锁屏小部件文档,我实现了它,但这不是自动放在主锁窗口上的内容.我正在寻找提供Media Lock-screen窗口(在Jelly Bean及以上版本中)的媒体控制解决方案,如Google Play音乐应用程序.
看看谷歌播放音乐锁,这显然不是锁定屏幕小部件.

我正在使用Glide从服务器上加载所有图像,但是我正在尝试以正确的方式设置它们以进行通知和RemoteControlClientCompat(这是锁定屏幕的酷事).我正在开发一个音乐播放器,所以每次更改一首歌时,通知的歌曲封面都必须改变.我有这个代码,它第一次工作(虽然图像是从url或drawable加载),但不是第二次调用时.图像不会改变!更改歌曲时会调用CustomNotification.并且在启动活动时调用RegisterRemoteClient.
如果这不是正确的方法,请说明如何.
public void CustomNotification() {
Log.d(TAG, "Set custom notification");
simpleRemoteView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_custom);
expandedRemoteView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_big);
mNotification = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_main_logo)
.setTicker(mSongTitle + " - " + mSongAuthors)
.setContentTitle(mSongTitle).build();
setRemoteListeners(simpleRemoteView);
setRemoteListeners(expandedRemoteView);
try {
//Check if playingSong has a cover url, if not set one from drawable
if(!playingSong.has("cover")){
mDummyAlbumArt = BitmapFactory.decodeResource(getResources(),R.drawable.image_song_album);
mDummyAlbumArt2 = BitmapFactory.decodeResource(getResources(),R.drawable.image_song_album);
mDummyAlbumArt3 = BitmapFactory.decodeResource(getResources(),R.drawable.image_song_album);
}else {
Glide.with(MainActivity.context)
.load(API.imgUrl(playingSong.getString("cover_img")))
.asBitmap()
.into(new SimpleTarget<Bitmap>(100, 100) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
mDummyAlbumArt = bitmap; …Run Code Online (Sandbox Code Playgroud) notifications android remoteview lockscreenwidget android-glide
我们如何将锁屏小部件添加到现有的小部件包中并仍然支持 iOS 15?:thinking_face: 例如,这不会编译
struct SecondExtraBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
DailyHeartRatesWidget()
if #available(iOSApplicationExtension 16.0, *) {
LockScreenRecoveryScoreWidget()//Requires iOS 16?
} else {
// Fallback on earlier versions
}
}
}
Run Code Online (Sandbox Code Playgroud) 我要求用户需要能够通过Windows锁定屏幕启动我的应用程序。搜索www后,发现很难从锁定屏幕挂接热键(如果不是不可能的话)。
然后我发现这篇文章使用
Microsoft.Toolkit.Uwp.Notifications.TileContent
Run Code Online (Sandbox Code Playgroud)
将通知发送到锁定屏幕。
我发现没有办法向其中添加一些按钮或类似控件,TileContent所以我尝试了
Microsoft.Toolkit.Uwp.Notifications.ToastContent
Run Code Online (Sandbox Code Playgroud)
我成功添加了一个按钮,并且可以显示ToastNotification如下内容
ToastContent content = new ToastContent()
{
Duration = ToastDuration.Long,
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Attribution = new ToastGenericAttributionText()
{
Text = "Hello World"
}
}
},
Actions = new ToastActionsCustom()
{
Buttons = {
new ToastButton ("mycontent", "myargs")
}
}
};
var notification = new ToastNotification(content.GetXml());
ToastNotificationManager.CreateToastNotifier().Show(notification);
Run Code Online (Sandbox Code Playgroud)
使用这种方法,我有一个问题,即ToastNotification在特定时间后消失。该ToastContent.Duration属性不能设置为“连续”或类似的东西。
ToastNotification?我需要在 Android 的锁定屏幕上显示自定义屏幕。从逻辑上讲,我想在手机锁定时显示一个屏幕(一项活动)。
[
]
我尝试了多种方法来实现此功能,但还没有成功。我关注的一些链接是:
截至目前,当应用程序处于前台状态时,我可以在锁定屏幕上显示自定义屏幕,但当应用程序处于后台/终止状态时,无法在锁定屏幕上显示自定义屏幕。请建议我的代码片段中缺少什么。
清单.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lockscreen">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round">
<activity
android:name=".sample2.screen.LockScreenActivity"
android:excludeFromRecents="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:showOnLockScreen="true"
android:turnScreenOn="false"
android:noHistory="true"
android:exported="true">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".sample2.utils.LockscreenService" >
</service>
<receiver
android:name=".sample2.utils.LockscreenIntentReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver> …Run Code Online (Sandbox Code Playgroud) android ×3
lockscreen ×2
c# ×1
ios ×1
java ×1
react-native ×1
remoteview ×1
swiftui ×1
toast ×1
uwp ×1
widgetkit ×1