2017-05-09 59 views
0

我已经firebase消息服务代码中检查通知标题,如果它包含某些文本&是在webview中的某个页面上,它显示一个吐司&刷新页面。删除过滤器收到通知

现在的事情是我想删除下面的线,我称之为文本过滤器:

if (title.contains("Added")) { 

谁能告诉怎么下面的代码修改?

public class FcmMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     super.onMessageReceived(remoteMessage); 

     String title = remoteMessage.getNotification().getTitle(); 
     final String message = remoteMessage.getNotification().getBody(); 



     if (title.contains("Added")) { 
      Handler handler = new Handler(Looper.getMainLooper()); 
      handler.post(
        new Runnable() { 
         @Override 
         public void run() { 

          Log.d("webUrl",""+MainActivity.mWebview.getUrl()); 

          if(MainActivity.mWebview.getUrl().contains("http://example.com")) { 
           Toast.makeText(FcmMessagingService.this, message, Toast.LENGTH_SHORT).show(); 
           MainActivity.reLoad(); 
          } 
          } 
        } 
      ); 

    }else{ 
      Intent intent = new Intent(this, MainActivity.class); 
      intent.putExtra("value", "kh"); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 
      Uri sounduri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); 
      notificationBuilder.setContentTitle(title); 
      notificationBuilder.setContentText(message); 
      notificationBuilder.setSmallIcon(R.mipmap.ic_icon); 
      notificationBuilder.setSound(sounduri); 
      notificationBuilder.setAutoCancel(true); 
      notificationBuilder.setContentIntent(pendingIntent); 
      NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

      notificationManager.cancel(0); 
      notificationManager.notify(0, notificationBuilder.build()); 


     } 


    } 


} 
+0

你是什么意思的 “仅保留网页过滤器。”?你的页面过滤器在哪里? – FAT

+0

@FerdousAhamed更新了问题。我想删除“if(title.contains(”Added“)) ” – Observer

+0

实际上你的要求是什么?你想要什么标题和消息的价值? – FAT

回答

0

试试这个:

if(MainActivity.mWebview.getUrl().contains("http://example.com")) { 
     Handler handler = new Handler(Looper.getMainLooper()); 
     handler.post(
       new Runnable() { 
        @Override 
        public void run() { 

         Log.d("webUrl",""+MainActivity.mWebview.getUrl()); 
         Toast.makeText(FcmMessagingService.this, message, Toast.LENGTH_SHORT).show(); 
         MainActivity.reLoad(); 
        } 
       }); 
    } else { 
     Intent intent = new Intent(this, MainActivity.class); 
     intent.putExtra("value", "kh"); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 
     Uri sounduri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); 
     notificationBuilder.setContentTitle(title); 
     notificationBuilder.setContentText(message); 
     notificationBuilder.setSmallIcon(R.mipmap.ic_icon); 
     notificationBuilder.setSound(sounduri); 
     notificationBuilder.setAutoCancel(true); 
     notificationBuilder.setContentIntent(pendingIntent); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.cancel(0); 
     notificationManager.notify(0, notificationBuilder.build()); 
    } 
+0

给出错误 - 方法getUrl必须从UI线程调用,当前推断的线程是工作线程 – Observer