我已经为我的应用程序设置了一个通知,代码如下:
public int getNotification( View view) {
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(getActivity() ,RouteMap.class );
intent.putExtra("Stop Ride",true);
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), (int) System.currentTimeMillis(), intent, 0) ;
if (Build.VERSION.SDK_INT < 16) {
getToast("API below 16 ...notification not supported");
} else {
Notification notify = new Notification.Builder(getActivity())
.setSmallIcon(R.drawable.icon1)
.setContentTitle("Car Rental")
.setContentText("Click to view ")
.setOngoing(true)
.setContentIntent(pendingIntent)
.addAction(R.drawable.icon3,"View ",pendingIntent)
.addAction(R.drawable.alert_icon,"Stop Ride", pendingIntent )
.build();
notificationManager.notify(notificationID, notify);
}
return notificationID;
}
public void removeNotification() {
NotificationManager manager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(
notificationID);
getToast("Notification Removed");
}
应用程序显示通知,但在单击通知按钮时不执行任何操作 如果要在我的代码中添加某些内容,请帮助我。
更新: 由于此方法在 fragment 类中
我已经按照下面的建议更改了一些代码,但是没有用:
public int getNotification( View view) {
// NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(getActivity(), RouteMap.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (Build.VERSION.SDK_INT < 16) {
getToast("API below 16 ...notification not supported");
} else {
Notification notify = new Notification.Builder(getActivity())
.setSmallIcon(R.drawable.icon12)
.setContentTitle("Car Rental")
.setContentText("Click to view ")
.setOngoing(true)
.setSound(soundUri)
.setContentIntent(pendingIntent)
.addAction(R.drawable.icon3, "View ", pendingIntent)
.addAction(R.drawable.alert_icon, "Stop Ride", pendingIntent)
.build();
notificationManager.notify(notificationID, notify);
}
return notificationID;
}
提前致谢..
最佳答案
这是我在我的应用中使用的。
Intent i = new Intent(ctx, NotifReceiver.class);
PendingIntent pi = PendingIntent.getActivity(ctx, notifNum, i, 0);
Notification notif = new Notification.Builder(ctx)
.setContentTitle("MyPower Reminder")
.setContentText(contentTxt)
.setSmallIcon(R.drawable.ic_mypower4)
.setContentIntent(pi)
.setSound(notifSound)
//.addAction(0, "View Full Reminder", pi)
.build();
NotificationManager notifMgr = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
notifMgr.notify(0, notif);
.addAction(0, "View Full Reminder", pi) 也像点击通知一样工作。它看起来像一个带有您设置的文本的按钮。所以我不使用,我喜欢保留我的代码。
关于android - 通知按钮点击不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36277402/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
有人知道在发布新版本的Ruby和Rails时收到电子邮件的方法吗?他们有邮件列表,RubyonRails有一个推特,但我不想听到那些随之而来的喧嚣,我只想知道什么时候发布新版本,尤其是那些有安全修复的版本。 最佳答案 从therailsblog获取提要.http://weblog.rubyonrails.org/feed/atom.xml 关于ruby-on-rails-如何在发布新的Ruby或Rails版本时收到通知?,我们在StackOverflow上找到一个类似的问题:
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模
我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o
这段代码似乎创建了一个范围从a到z的数组,但我不明白*的作用。有人可以解释一下吗?[*"a".."z"] 最佳答案 它叫做splatoperator.SplattinganLvalueAmaximumofonelvaluemaybesplattedinwhichcaseitisassignedanArrayconsistingoftheremainingrvaluesthatlackcorrespondinglvalues.Iftherightmostlvalueissplattedthenitconsumesallrvaluesw
你能解释一下吗?我想评估来自两个不同来源的值和计算。一个消息来源为我提供了以下信息(以编程方式):'a=2'第二个来源给了我这个表达式来评估:'a+3'这个有效:a=2eval'a+3'这也有效:eval'a=2;a+3'但我真正需要的是这个,但它不起作用:eval'a=2'eval'a+3'我想了解其中的区别,以及如何使最后一个选项起作用。感谢您的帮助。 最佳答案 您可以创建一个Binding,并将相同的绑定(bind)与每个eval相关联调用:1.9.3p194:008>b=binding=>#1.9.3p194:009>eva
基本上,我试图在用户单击链接(或按钮或某种类型的交互元素)时执行Rails方法。我试着把它放在View中:但这似乎没有用。它最终只是在用户甚至没有点击“添加”链接的情况下调用该函数。我也用link_to试过了,但也没用。我开始认为没有一种干净的方法可以做到这一点。无论如何,感谢您的帮助。附言。我在ApplicationController中定义了该方法,它是一个辅助方法。 最佳答案 View和Controller是相互独立的。为了使链接在Controller内执行函数调用,您需要对应用程序中的端点执行ajax调用。该路由应调用rub
我在ruby表单中有一个提交按钮f.submitbtn_text,class:"btnbtn-onemgt12mgb12",id:"btn_id"我想在不使用任何javascript的情况下通过ruby禁用此按钮 最佳答案 添加disabled:true选项。f.submitbtn_text,class:"btnbtn-onemgt12mgb12",id:"btn_id",disabled:true 关于ruby-on-rails-如何在Rails中添加禁用的提交按钮,我们在St