标签: android-remoteview

如何使用RemoteViews更新通知?

我正在使用RemoteViews自定义创建通知,该自定义Service以前台模式运行通知(即,只要用户可以看到通知,服务就会保持活动状态).通知设置为正在进行,因此用户无法将其滑动.

我想更改示例中显示的位图ImageView,包含在远程视图的布局中或更改文本值TextView.远程视图中的布局使用XML布局文件设置.

我的问题是,一旦通知被创建并且对用户可见,如果我调用任何RemoteViews类似于setImageViewResource()更改中Bitmap显示的任何功能ImageView,则更改是不可见的,除非我setImageViewResource()之后打电话给我打电话:

NotificationManager.notify( id, notification );
Run Code Online (Sandbox Code Playgroud)

要么

Service.startForeground(id,notification);
Run Code Online (Sandbox Code Playgroud)

这对我来说听起来不对.我无法相信要RemoteViews在已创建的通知中更新UI,我必须重新初始化通知.如果我对Button通知有控制权,它会在触摸和释放时自行更新.所以必须有一种方法可以做到这一点,但我不知道如何.

这是我的代码,它在我的Service实例中创建通知:

this.notiRemoteViews = new MyRemoteViews(this,this.getApplicationContext().getPackageName(),R.layout.activity_noti1);

Notification.Builder notibuilder = new Notification.Builder(this.getApplicationContext());
notibuilder.setContentTitle("Test");
notibuilder.setContentText("test");
notibuilder.setSmallIcon(R.drawable.icon2);
notibuilder.setOngoing(true);

this.manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
this.noti = notibuilder.build();
this.noti.contentView = this.notiRemoteViews;
this.noti.bigContentView = this.notiRemoteViews;
this.startForeground(NOTIFICATION_ID, this.noti);
Run Code Online (Sandbox Code Playgroud)

并且"强制"UI更改为通知的功能:

public void updateNotiUI(){
    this.startForeground(NOTIFICATION_ID, this.noti);
}
Run Code Online (Sandbox Code Playgroud)

MyRemoteViews课堂上,如果需要,我这样做是为了对UI进行更改:

this.setImageViewResource(R.id.iconOFF, R.drawable.icon_off2);
this.ptMyService.updateNotiUI();
Run Code Online (Sandbox Code Playgroud)

谁能告诉我更新RemoteViews通知中UI组件的正确方法是什么?

android android-notifications android-remoteview

32
推荐指数
2
解决办法
2万
查看次数

Android USB调试端口前向错误

我有android远程调试端口转发的问题.我需要在44300-44399范围内获得端口,因为Visual Studio调试只允许在这些端口上使用SSL,但即使文档说它应该可以在1024-65535的任何端口上工作,我仍然无法转发这些端口.任何人遇到这个或知道我怎么能弄清楚为什么端口不转发?我知道连接在那里,因为其他端口工作正常.在此输入图像描述

android portforwarding android-webview google-chrome-devtools android-remoteview

12
推荐指数
1
解决办法
1007
查看次数

在通知中播放/暂停按钮图像,Android

我已经实现了音乐播放器,在播放流音频时会触发自定义通知.

一切正常,我可以使用通知中的按钮播放/暂停音频.唯一的问题是图像按钮:单击按钮无法更改图像以指示播放/暂停.

在RemoteReceiver中使用remoteViews.setImageViewResource()不起作用.控件是使用BroadcastReceiver完成的,这是从玩家活动中触发通知的代码:

  public void setNotification(String songName){
      String ns = Context.NOTIFICATION_SERVICE;
      NotificationManager notificationManager = (NotificationManager) getSystemService(ns);

      @SuppressWarnings("deprecation")
      Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());

      RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.notification_view);
      notificationView.setImageViewResource(R.id.button1, R.drawable.pause);
      notificationView.setTextViewText(R.id.textView1, songName);

      //the intent that is started when the notification is clicked (works)
      Intent notificationIntent = new Intent(this, PlayerActivity.class);
      PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

      notification.contentView = notificationView;
      notification.contentIntent = pendingNotificationIntent;     

      Intent switchIntent = new Intent("com.example.test.ACTION_PLAY");
      PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

      notificationView.setOnClickPendingIntent(R.id.play_pause, pendingSwitchIntent);
      notificationManager.notify(1, notification); …
Run Code Online (Sandbox Code Playgroud)

notifications android media-player android-remoteview

11
推荐指数
1
解决办法
1万
查看次数

RemoteView addView无法正常工作

我有一个应用程序小部件,我想添加视图(TextView等等),RemoteView但它永远不会出现.
这里是代码:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
    newView.setTextViewText(R.id.textUser, "1234");
    views.addView(views.getLayoutId(), newView);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?


这就是我最终做的事情:

RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
    newView.setTextViewText(R.id.textUser, "1234");
ComponentName thisWidget = new ComponentName(this,WidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
    manager.updateAppWidget(thisWidget, newView);
Run Code Online (Sandbox Code Playgroud)

android android-widget remoteview android-remoteview

9
推荐指数
1
解决办法
1万
查看次数

Android 4.x RemoteControlClient.setTransportControlFlags()不起作用?

我正在尝试使用RemoteControlClient类来支持我的应用程序的锁屏播放器.一个问题是设置传输控制标志似乎无法正常工作.

例如,我试图只显示播放/停止图标没有上一个/下一个:

mRemoteControlClient.setTransportControlFlags(
                        RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
                        RemoteControlClient.FLAG_KEY_MEDIA_STOP);
Run Code Online (Sandbox Code Playgroud)

这显示了之前的图标和暂停图标!为什么?

为了使事情更糟按下停止/播放按钮时,你只收到KEYCODE_MEDIA_PLAY_PAUSE时,你应该得到KEYCODE_MEDIA_STOPKEYCODE_MEDIA_PLAY.

如果我发现我正确地做到这一点,这在Android方面是令人沮丧的糟糕发展.

android remote-control android-remoteview

9
推荐指数
1
解决办法
1308
查看次数

Android 5+ remoteviews涟漪效应

是否可能对作为远程视图一部分的按钮产生连锁效应?(使用自定义布局或窗口小部件的通知)

我尝试将按钮背景设置为drawable notification_material_media_action_background:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/ripple_material_dark"/>
Run Code Online (Sandbox Code Playgroud)

但它没有效果.通知源代码中使用相同的背景,并且通知按钮会产生连锁反应.这是来自Notification source的代码,它创建了动作按钮(具有涟漪效果):

   private RemoteViews More ...generateMediaActionButton(Action action) {
            final boolean tombstone = (action.actionIntent == null);
            RemoteViews button = new RemoteViews(mBuilder.mContext.getPackageName(),
                    R.layout.notification_material_media_action);
            button.setImageViewResource(R.id.action0, action.icon);
            button.setDrawableParameters(R.id.action0, false, -1,
                    0xFFFFFFFF,
                    PorterDuff.Mode.SRC_ATOP, -1);
            if (!tombstone) {
                button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
            }
            button.setContentDescription(R.id.action0, action.title);
            return button;
        }
Run Code Online (Sandbox Code Playgroud)

唯一不同的是这条线:

 button.setDrawableParameters(R.id.action0, false, -1,
                        0xFFFFFFFF,
                        PorterDuff.Mode.SRC_ATOP, -1);
Run Code Online (Sandbox Code Playgroud)

但是这个方法是@hide所以它不能被调用.

知道如何添加涟漪效果吗?谢谢!

android android-widget android-notifications android-remoteview material-design

7
推荐指数
1
解决办法
455
查看次数

是否可以在android推送通知中添加视频?

是否可以像在 iOS 中那样将视频嵌入到 android 丰富的通知中?我知道 android 官方仍然不支持,但它可能是一些即兴创作的棘手方法?:)

提前致谢。

java android push-notification android-remoteview android-push-notification

7
推荐指数
1
解决办法
3931
查看次数

动态更改android通知文本

我正在尝试通过控件为音乐播放器发出通知.我正在成功地听取按钮单击事件并且正在正常触发功能.我遇到的唯一问题是更改这些点击事件的通知文本.这就是我想要的.

这是接收器成功接收呼叫并完美地触发每一行.但我不能改变文本.我想我必须将内容视图重置为通知.如果是这样,我该怎么做?

@Override
public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
    if (action.equals("stop")) {
        ABCFragment.stopSong();
        Log.d("Notification","Stopping");
    }else if (action.equals("play")) {
        ABCFragment.togglePlayPause();
        Log.d("Notification","Toggle Play/Pause");
        RemoteViews contentView = new RemoteViews(context.getPackageName(),R.layout.notification_layout);
        contentView.setTextViewText(R.id.songName, "SOME NEW SONG");
    }else if (action.equals("next")) {
        ABCFragment.playNextSong();
        Log.d("Notification","Next");
    }
}
Run Code Online (Sandbox Code Playgroud)

方案:

我更新了我的Notification类构造函数以传递额外的参数并使其正常工作!

@Override
public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
    if (action.equals("stop")) {
        ABCFragment.stopSong();
        Log.d("Notification","Stopping");
    }else if (action.equals("play")) {
        ABCFragment.togglePlayPause();
        Log.d("Notification","Toggle Play/Pause");
        new ABCNotification(context, "SOME NEW SONG");
    }else if (action.equals("next")) {
        ABCFragment.playNextSong();
        Log.d("Notification","Next"); …
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-remoteview

6
推荐指数
1
解决办法
4764
查看次数

如何在将在 RemoteView 中使用的可绘制对象上设置滤色器?

我有一个必须应用过滤器的ImaveViewon a 。RemoteView当我不在的时候,RemoteView这就是我所做的,而且效果很好:

    Drawable icon = getResources().getDrawable(R.drawable.icon);
    icon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    image.setImageDrawable(icon);
Run Code Online (Sandbox Code Playgroud)

似乎RemoteView没有办法让我设置不是资源的可绘制对象。我该怎么做呢?

谢谢。

android android-widget android-notifications remoteview android-remoteview

6
推荐指数
2
解决办法
3395
查看次数