- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在通知中使用三个操作按钮来控制媒体服务,但很难找到代码的工作示例:Vogella 有一个教程,但他使用一个按钮并打开一个 Activity 而不是服务。我已经找到了其他几个此类教程和示例,但没有一个具有三个工作操作按钮,这些按钮具有类似的教程,这些教程演示了服务和多个操作的 Intent 的构造,以及 stackoverflow 上操作按钮使用的最新示例都适用于较低的android 版本,使用单一 Intent 按钮,...
这是我想用来设置通知的代码:
//individual intents for each action???
Intent Back = new Intent(this, MusicService.class );
Back.putExtras("back", 1);
Back.putExtras("play", 0);
Back.putExtras("next", 0);
Intent Play = new Intent (this, MusicService.class);
Back.putExtras("back", 0);
Back.putExtras("play", 1);
Back.putExtras("next", 0);
Intent Next = new Intent (this, MusicService.class);
Next.putExtras("back", 0);
Next.putExtras("play", 0);
Next.putExtras("next", 1);
//do I need to make three pending intents????
PendingIntent pIntentback = PendingIntent.getService(this, 0, Back, 0);
PendingIntent pIntentplay = PendingIntent.getService(this, 0, Play, 0)
PendingIntent pIntentnext = PendingIntent.getService(this, 0, Next, 0)
Notification noti = new Notification.Builder(this)
.setContentTitle("Juke Box Hero")
.setContentText("Playing ")
.setSmallIcon(R.drawable.ic_launcher)
.addAction(R.drawable.back, "", pIntentback)
.addAction(R.drawable.play, "", pIntentplay)
.addAction(R.drawable.next, "", pIntentnext)
.build();
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
noti.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
我有几个问题...
1) 上面的代码是我应该如何设置操作按钮、 Intent 和待定 Intent ?
2) 因为我想接收服务中未决 Intent 所包含的 Intent ,我调用 getService 而不是 getActivity 是否正确?
3) 如果我能够直接在 MusicService 类中接收 Intent ,我如何在不重新启动服务的情况下接收服务中的 Intent (从而丢失已经存储在内存中的数据)?
4) 或者我是否需要构建一个接收器类来扩展 BroadcastReceiver 类并在 list 中注册它,然后将相应的 Intent 发送到 MusicService 类?
请理解我非常愿意研究和编写代码——并且在提出问题之前已经研究了好几天,但我需要这些问题的直接答案...
非常感谢帮助和指导
最佳答案
1) 上面的代码是我应该如何设置操作按钮、 Intent 和待定 Intent ?
回答#1)不,为了设置触发和激活适当 Activity 或服务的未决 Intent , Intent 应该有一个 setAction(在这里插入你的 Action 名称)并且相应的未决 Intent 应该使用更新当前标志未决 Intent (请参阅下面对第 2 条的回答中的示例代码)
Intent 应该是这样的......
Intent Play = new Intent (this, Receiver.class);
Play.setAction("Play");
Play.putExtra("back", 0);
Play.putExtra("play", 1);
Play.putExtra("next", 0);
2) 因为我想接收服务中未决 Intent 所包含的 Intent ,我调用 getService 而不是 getActivity 是否正确?
回答 #2) 不,我使用了 broadcastreciever 类来捕获通知发送的 Intent ;有必要使用 getBroadcast 并确保以下列方式附加应用程序上下文(可能不是必需的,但似乎是个好主意)--
PendingIntent pIntentback = PendingIntent.getBroadcast(this.getApplicationContext(), 0, Play, PendingIntent.FLAG_UPDATE_CURRENT);
3) 如果我能够直接在 MusicService 类中接收 Intent ,我如何在不重新启动服务的情况下接收服务中的 Intent (从而丢失已经存储在内存中的数据)?
回答#3)我回避了这个问题,但在对这个想法进行了一些研究之后,您似乎可以在服务类中构建一个接收器来处理这种情况......我现在无法提供详细信息这样的效果和要求,但是我使用的外部广播接收器系统不会中断音乐服务或重置已经通过原始服务 Intent 传递的信息......
4) 或者我是否需要构建一个接收器类来扩展 BroadcastReceiver 类并在 list 中注册它,然后将相应的 Intent 发送到 MusicService 类?
回答 #4)如上所述,构建服务外部的接收者类不是必需的,但在不损坏功能完善的服务类的情况下似乎最容易操作……接收者类中的个人 Intent 是通过附加的操作键识别,然后构建所需的操作特定 Intent 以发送到服务类...
关于Android 4 及更高版本,多操作通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18758616/
我有一个 DIV #page,如果我在顶部添加边距,突然出现一个滚动条,即使该元素不大于主体。我怎样才能去掉滚动条? (参见 Fiddle) 我的 HTML I am a div siz
function getClosestValue(standardArray, targetVal) { standardArray = standardArray.sort(function(a,
我有 318x424 的书籍封面图片,我想做的是指定一张图片,并在其下方添加一个文本链接。初始 src 是 about:blank,这样如果响应式设计不显示框架,它就不会占用用户带宽。 框架的 HTM
我被这个问题困了两天了,还是没搞定。 基本上,我有一个二维数组,其中包含某些数字(在给定范围内)之间的关系: 0 = 顺序无关紧要 1 = 第一个数字(左栏中的数字)应该是第一个 2 = 第二个数字(
只有当我在更高的 API 上进行调试时,我才会强制关闭脚本:16,但是当涉及到 API 时它工作正常:10。这可能是我的项目设置问题吗? 这是对服务器的简单请求,以获取 fragment 中的类别列表
给定下表books id | listorder ----+----------- 3 | 1 2 | 2 1 | 3 4 |
我想要那个密码切换功能,好像TextInputLayout有这个功能,而不是 TextInputEditText .但是正如您在下面的代码中看到的,即使我将高度设置为 wrap_content和 ap
似乎从 读取给出空列表,它主要发生在延迟较高的网络上的主机上。是否有更强大的与远程主机交互的方式? use Net::SSH2; # my $ssh = Net::SSH2->new(); # ..
为了在 Play 商店中发布我的应用程序,我必须将 TargetSdkVersion 从 23 更改为 26。在我更改它之前,该应用程序运行良好!现在应用程序在启动时崩溃。我想通了,问题出在这两行:
我尝试了很多解决方案,但找不到一个。我有 3 个不同的列,其中包含不同类型的文本,我需要它们具有相同的高度。但它们是这样不同的:colums有人可以帮忙吗? 代码: .col-sm-2{
我尝试将一个 div 相对于其具有负顶值的父级定位。这工作正常,现在的问题是这个 div,即使它有一个负的 top 值也会使父 div 更大。 我该怎么做才能让父 div 不那么大? Here's a
这是一个一般性问题,可能适用于任何给定的语言,如 C、C++、Java 等。 我认为无论以何种方式实现它,都不会比使用 2 个循环更高效,后者的效率为 n^2。 for(i=0;i O(1) ),要么
我需要查找所有有订单的家庭。我根本不关心订单的数据,只关心它的存在。 (使用 SQL Server) 这样说是不是更有效率: SELECT HouseholdID, LastName, FirstNa
我有一个 UINavigationController,在屏幕顶部有一个 UINavigationBar,在底部有一个 UIToolbar。我想让工具栏高一点。这是我的代码: CGRect toolb
我正在使用自定义字体。该字体在我的 Windows PC 上完美运行,但在我的 Mac (Yosemite OSX) 上运行不佳。正如您在图片中看到的,Mac 上的字体比 Windows 上的字体稍大
我正在尝试使用 FaSTLane 将我的应用程序作为 alpha 版本部署到 Play 商店,但出现此错误: Google Api 错误:multiApkShadowedActiveApk:任何设备都
我在这里找不到神奇的调味料。看起来 API 不支持它,所以我想我正在寻找一些 CSS 来使 slider 更大。 我得到的是左边的,但我想把它设计成右边的样子?任何 CSS 技巧或以前有人这样做过。
如果我运行这段代码: float a=1.123456789; printf("The float value is %f\n",a); double b=1.123456789876543 prin
我正在尝试使用 strip binary 来剥离我的目标文件。我在 gcc-7 上构建了最新的 binutils,但我的代码库使用 gcc-4.9.2。Binutils 是为 64 位架构构建的,我的
有没有办法让 iPhone 应用的“内容”区域感知到更大的导航栏? 类似这些问题: iOS: Adding a fixed image just below the navigation bar iO
我是一名优秀的程序员,十分优秀!