- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经创建了一个支持我的手持应用程序的 android wear 应用程序。显示通知和相关操作的 Android Wear 应用。
我已经创建了 android wear 通知并添加了暂停、恢复和停止两个 Action
我需要用动态恢复 Action 替换暂停 Action ,这意味着如果用户按下暂停 Action 需要更改为恢复 Action 。
我的代码是
Intent pauseIntent = new Intent(getApplicationContext(), PauseActivity.class);
PendingIntent pausePendingIntent = PendingIntent.getActivity(getApplicationContext(),
0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopIntent = new Intent(getApplicationContext(), StopActivity.class);
PendingIntent stopPendingIntent = PendingIntent.getActivity(getApplicationContext(),
0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.icon)
.setContentTitle("Swipe up to view")
.setDeleteIntent(deletePendingIntent)
.extend(new WearableExtender()
.setDisplayIntent(displayPendingIntent))
.addAction(R.drawable.pause_btn, "Pause", pausePendingIntent)
.addAction(R.drawable.stop_btn, "Stop", stopPendingIntent)
.build();
我的要求是当用户点击暂停按钮时,我需要通过恢复图标来更改它。
预先感谢所有...我的屏幕看起来像
最佳答案
您只需在用户点击该操作以刷新它时发布新通知即可。
旧通知将更新,因此在发布新通知时将“暂停”图标更改为“恢复”图标 + 对标签执行相同操作。
BroadcastReceiver
像这样定义你的 Intent :
Intent pauseIntent = new Intent(MediaPlayerActionsReceiver.ACTION_PAUSE, null, context, MediaPlayerActionsReceiver.class);
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(context, 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent resumeIntent = new Intent(MediaPlayerActionsReceiver.ACTION_RESUME, null, context, MediaPlayerActionsReceiver.class);
PendingIntent resumePendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopIntent = new Intent(MediaPlayerActionsReceiver.ACTION_STOP, null, context, MediaPlayerActionsReceiver.class);
PendingIntent stopPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
它们都将传送到同一个组件 (MediaPlayerActionsReceiver
),但声明的操作不同。
然后创建您的 MediaPlayerActionsReceiver 类:
public class MediaPlayerActionsReceiver extends BroadcastReceiver {
public final static String ACTION_PAUSE = "com.example.package.receiver.action_pause";
public final static String ACTION_RESUME = "com.example.package.receiver.action_resume";
public final static String ACTION_STOP = "com.example.package.receiver.action_stop";
@Override
public void onReceive(Context context, Intent intent) {
if(intent==null)
return;
final String action = intent.getAction();
if(ACTION_PAUSE.equals(action)) {
// handle pause action and refresh notification
} else if(ACTION_RESUME.equals(action)) {
// handle resume action and refresh notification
} else if(ACTION_STOP.equals(action)) {
// handle stop action and refresh notification
}
}
}
最后一步是在 AndroidManifest
中声明您的接收器:
<receiver android:name="com.example.package.receiver.MediaPlayerActionsReceiver" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="com.example.package.receiver.action_pause" />
<action android:name="com.example.package.receiver.action_resume" />
<action android:name="com.example.package.receiver.action_stop" />
</intent-filter>
</receiver>
关于android - 如何在 Android Wear 中动态更改 Action 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24995197/
我一直在 list 中使用以下意图过滤器,一切正常: 这已被弃用,所以我尝试使用: 我可以正常接收消息,但 onPeerConnected 现在永远不会被调用。 public class
我一直在 list 中使用以下意图过滤器,一切正常: 这已被弃用,所以我尝试使用: 我可以正常接收消息,但 onPeerConnected 现在永远不会被调用。 public class
最新的Android Wear更新随附对ChannelApi的支持,可用于向可穿戴设备或手持设备发送文件或从可穿戴设备或手持设备发送文件。问题是我找不到有关如何使用此功能的单个示例。 Android示
我已经根据官方 API 更新了我的 Android Wear 表盘,总体来说进展顺利。然而,我坚持的一件事是从 Android Wear 应用程序中启动配套(手持)配置事件。我只是无法在 AW 应用程
我在 Moto 360 上启用了蓝牙调试并在我的 Nexus4 上启用了 Android Wear 应用程序。 状态显示目标:已断开 从我的电脑转发端口显示状态主机将更改为已连接,但目标状态仍保持断开
Android Wear 生态系统似乎是围绕用户将与之交互然后关闭的快速任务构建的。这对大多数应用程序都很有效,但是对于一个涵盖长时间运行的任务并且在 watch 休眠时不应自动关闭的应用程序呢? 我
我正在 Android 中开发一个应用程序以及 Android Wear 支持。在查看来自 https://developer.android.com/training/building-wearab
我打开了 USB 调试,我显示目标已连接,但我无法连接主机。 当我在我的 PC 上运行以下命令时,我得到指示该命令未完成的输出。 adb forward tcp:4444 localabstract:
据我所知,有两种方法可以为 Android Wear 中的通知设置背景图像。为了记录,两者都以: Bitmap bitmap; Notification.Builder bob = new
我正在编写一个自定义 Android Wear 应用程序,该应用程序应该向连接的主机设备(电话)发送一次性消息。通过 API 挖掘,我发现以下教程应该可以很好地工作:http://developer.
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在尝试将文件从我的 Google Wear 发送到我的 Nexus 5。我已经阅读了一些教程并想出了以下代码,但我的手机没有收到文件。 手机: private GoogleApiClient mG
我正在尝试为 Google Wear 设置我的开发环境并遵循了 Google 的 instructions但是一旦我设置了端口转发 (adb -d forward tcp:5601 tcp:5601)
在开发 Android Wear 表盘时,如何检测屏幕是否是圆形且有下巴(又名扁平轮胎带),如 Moto 360?我尝试了 onSurfaceChanged,但宽度和高度是相同的。 我在有下巴的模拟器
我正在为 Android Wear 编写应用程序,我需要在关闭应用程序时实现与 Android Wear 上的 Google map 应用程序类似的行为。 通常,“Swipe-To-Dismiss”手
我正在开发一款适用于 Android Wear 的应用程序,它可以在手机上启动一项 Activity 。一切都很好,但我不想依赖手机上不断运行的后台服务来接收这条消息。理想情况下,我会让 Wearab
我尝试通过启动语音命令启动我的穿戴应用程序。我按照文档 Adding Voice Capabilities .但是,当我尝试通过说(OK Google)“启动我的应用程序”来启动应用程序时,我会收到与
当我使用数字表冠时,我的列表没有滚动 这就是我所做的; public class MainActivity extends Activity { @Override protecte
根据指南: https://developer.android.com/design/wear/patterns.html#Continuing “在必须使用手机的情况下,一旦点击操作按钮并在手机上打
有人可以分享有关使用 Android Wear 使用手腕运动(与触摸屏上的滑动运动相反)进行手势检测的信息吗? API 中有对此的官方支持吗?如果没有,您认为可以通过自定义 ROM 启用此功能吗?考虑
我是一名优秀的程序员,十分优秀!