【发布时间】:2016-01-31 16:42:13
【问题描述】:
我正在尝试通过 onprogress 更新方法仅显示一次通知。存在允许显示通知的条件。问题是它在第一个通知之后继续显示通知,并且手机不断响铃和振动。我只想收到一个通知,通知某事并停止。有可能吗?有人可以帮忙并提出替代方法。谢谢。
这是我的 onPorgressUpdate 方法的代码:
protected void onProgressUpdate(byte[]... values) {
super.onProgressUpdate(values);
String command=new String(values[0]);//get the String from the recieved bytes
String[] parts= command.split(",");
String part1=parts[0];
String part2=parts[1];
temp.setText(part1);
humi.setText(part2);
if(Integer.parseInt(part2)>70)
{
NotificationCompat.Builder builder=new NotificationCompat.Builder(this.context);
builder.setContentTitle("AM Home Automation");
builder.setContentText("humi");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setTicker("alert");
builder.setDefaults(Notification.DEFAULT_ALL);
notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
【问题讨论】:
标签: android notifications async-onprogressupdate