0

私のアプリで受け取った(firebaseプッシュ)通知でこの問題があります。彼らはちょうど1秒間表示され、その後消えます。私は間違って何をしたのか分かりません。ここに私のコードは次のとおりです。Firebase通知が一時的に表示されます

public class PushNotification extends FirebaseMessagingService 
{ 
    private Gson gson = new Gson(); 
    @Override 
    public void onMessageReceived(final RemoteMessage remoteMessage){ 
    String TAG = PushNotification.this.getClass().getName(); 
    Log.e("PushNotification", "From: " + remoteMessage.getFrom()); 

    // Check if message contains a data payload. 
    if (remoteMessage.getData().size() > 0) 
    { 
     Log.d("PushNotification", "Notification Received"); 

     for (String key : remoteMessage.getData().keySet()) 
     { 
      Object value = remoteMessage.getData().get(key); 
      String temp = String.format("%s %s (%s)", key, value.toString(), 
value.getClass().getName()); 
      Log.d("PushNotification", "key: "+ temp); 
     } 
    } 
    else Log.d("PushNotification", "NO DATA PAYLOAD"); 

    methodToHandleNotifications(remoteMessage.getData()); 


} 

private void methodToHandleNotifications(Map<String, String> data){ 
    CarInfo mCarInfo = 
gson.fromJson(data.get(Tags.PUSH_NOTIFICATION_KEY_CAR_INFO), CarInfo.class); 

    Intent resultIntent = new 
Intent(AppController.getInstance().getApplicationContext(), MyActivity.class); 
    resultIntent.putExtra("car", 
data.get(Tags.PUSH_NOTIFICATION_KEY_CAR_INFO)); 
    resultIntent.putExtra("id", mCarInfo.getId()); 
    resultIntent.putExtra("position", 0); 


showNotificationMessage(AppController.getInstance().getApplicationContext(), 






AppController.getInstance().getResources().getString(R.string.notification_auction 
    _ticker_from_own_company), 
       AppController.getInstance() 
          .getResources() 
         .getString(R.string.notification_auction_content, 
mCarInfo.getFullName()), 
      BuildConfig.URL_API_IMAGES + mCarInfo.getPhoto(), new 
DateTime().getMillis(), 
      resultIntent, mCarInfo.getId()); 
} 

private void showNotificationMessage(Context context, String title, String 
message, 
     String imageUrl, long timeStamp, Intent intent, Long carId) 
{ 
    NotificationUtils notificationUtils = new NotificationUtils(context); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    notificationUtils.showNotificationMessage(title, message, timeStamp, 
intent, imageUrl, 
      carId); 
    } 
} 

この私のNotificationUtilsクラス:

public class NotificationUtils 

は{

private Context mContext; 

public NotificationUtils(){ 
} 

public NotificationUtils(Context mContext){ 
    this.mContext = mContext; 
} 

public static boolean isAppIsInForeground(Context context) 
{ 
    boolean isInForeground = false; 
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH){ 
     List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses(); 
     for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses){ 
      if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND){ 
       for (String activeProcess : processInfo.pkgList){ 
        if (activeProcess.equals(context.getPackageName())){ 
         isInForeground = true; 
        } 
       } 
      } 
     } 
    }else{ 
     List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); 
     ComponentName componentInfo = taskInfo.get(0).topActivity; 
     if (componentInfo.getPackageName().equals(context.getPackageName())){ 
      isInForeground = true; 
     } 
    } 


    return isInForeground; 
} 
public void showNotificationMessage(final String title, final String message, 
     final long timeStamp, Intent intent, String imageUrl, Long carId){ 
    // Check for empty push message 
    if (TextUtils.isEmpty(message)) 
     return; 

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

    final PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0, intent, 
      PendingIntent.FLAG_CANCEL_CURRENT); 

    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); 

    final Uri alarmSound = Uri.parse(
      ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + mContext.getPackageName() + "/raw/notif"); 

    showNotification(mBuilder, title, message, timeStamp, resultPendingIntent, alarmSound, carId); 
} 

private void showNotification(
     NotificationCompat.Builder mBuilder, String title, 
     String message, long timeStamp, PendingIntent resultPendingIntent, Uri alarmSound, 
     Long carId){ 
    Notification notification; 
    notification = mBuilder.setTicker(title) 
          .setAutoCancel(true) 
          .setContentTitle(title) 
          .setContentText(message) 
          .setContentIntent(resultPendingIntent) 
          .setContentIntent(resultPendingIntent) 
          .setSound(alarmSound) 
          .setWhen(timeStamp) 
          .setPriority(Notification.PRIORITY_HIGH) 
          .setSmallIcon(getNotificationIcon()) 
          .setLargeIcon(
            BitmapFactory.decodeResource(mContext.getResources(), R.drawable.logo)) 
          .build(); 


    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(
      Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(carId.intValue(), notification); 
} 

private int getNotificationIcon(){ 
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP); 
    return useWhiteIcon ? R.drawable.notif_silhouette : R.drawable.notif; 
} 

は}

答えて

0

は、あなたが任意の場所の通知をクリアしていますか?これはデバイスの問題である可能性があります。他のデバイスで確認してください。

+0

いいえ...私はどこでも通知をクリアしていません.....私は別のデバイスでこれを試しました:それは同じ結果を得ることが判明...私は –

+0

実際にこれは私の質問に答えることはありません。 .... –