来自asynctack的通知OnProgressUpdate方法

问题描述:

我目前正在研究一个应用程序,它将不断从Web服务器获取传感器数据并将其显示在文本视图中。我正在使用Asynctask获取数据,并且OnprogressUpdate方法会不断获取新数据并显示它。只要传感器数据大于70,就会发送通知。来自asynctack的通知OnProgressUpdate方法

我遇到的问题是,只有一个通知发送时,数据大于70,当它减少,并重新增加没有通知发送。

当我删除布尔值时,我的手机继续发送通知,这很烦人。当数据大于70时,有没有办法发出通知,当数据减少并再次增加时,会发送另一个通知?

请注意,手机将接收2个传感器数据,它将不断显示文本视图中的数据。

下面是OnProgressMethod的代码。希望你们能帮我解答。谢谢。

OnProgressUpdate方法:

private boolean alreadyDisplayedNotification = false; 
 

 
protected void onProgressUpdate(byte[]... values) { 
 
\t \t 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(Float.parseFloat(part2)>70.00 && !alreadyDisplayedNotification) 
 
     { 
 
     \t NotificationCompat.Builder builder=new NotificationCompat.Builder(this.context); 
 
    \t \t \t builder.setContentTitle("AM Home Automation"); 
 
    \t \t \t builder.setContentText("humidity is high"); 
 
    \t \t \t builder.setSmallIcon(R.drawable.ic_launcher); 
 
    \t \t \t builder.setTicker("alert"); 
 
    \t \t \t builder.setDefaults(Notification.DEFAULT_ALL); 
 
    \t \t \t //builder.setSound(Uri.parse("android.resource://"+getPackageName()+"/"+R)); 
 
    \t \t \t 
 
    \t \t \t notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
 
    \t \t \t notificationManager.notify(1, builder.build()); 
 
    \t \t \t //notificationID--; 
 
    \t \t \t alreadyDisplayedNotification=true; 
 
    \t \t \t 
 
     } 
 
     
 
      
 
     
 
    }

我想:

if(Float.parseFloat(part2)<=70.00){ 
    alreadyDisplayedNotification=false; 
}