-1

이있는 내가 푸시 알림을 전송하고있는 방법이다 : -사용자가 로그 아웃하고 푸시 알림이 오면 내 앱이 자동으로 열립니다. 푸시 알림 클릭시 내 앱을 열고 싶습니다.

private void sendNotification(String msg) { 

     mNotificationManager = (NotificationManager) this 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
     PendingIntent contentIntent; 
     Intent intentblank = new Intent(this, LoginActivity.class); 
     intentblank.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intentblank); 


     Intent intent = new Intent(this, MainActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

     Log.e("message.....", msg); 


     if (msg.equals("You Have got New Message")) { 

      Log.e("msg occuring..", "intent enter in message..."); 
      intent.putExtra("KEYMESSAGE", "Message"); 

     } else { 

      Log.e("notification occuring..", "notification occurs....."); 
      intent.putExtra("KEYNOTIFICATION", "aman"); 


     } 



     if (sharedPreferencesUtilities.getEmail().equals("") || sharedPreferencesUtilities.getPassword().equals("")) { 
      Log.e("blank notification....", "blank notification..........................."); 
      contentIntent =PendingIntent.getActivity(this, 0, intentblank, 0); 
     } else { 
      contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
     } 


     mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) 
       .setSmallIcon(getNotificationIcon()) 
       .setContentTitle("Telepoh") 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) 
       .setContentText(msg) 
       .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); 

     mBuilder.setContentIntent(contentIntent); 
     mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; 
     mBuilder.getNotification().flags |= Notification.FLAG_ONGOING_EVENT; 
     mBuilder.setOngoing(false); 

     mBuilder.setAutoCancel(true); 


     mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 


    } 

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

나는 사용자가 푸시 알림에 클릭을 한 후 로그 아웃하면 로그인 페이지가 내 응용 프로그램의 열려 있음을합니다. 하지만 내 경우에는 사용자가 로그 아웃하면 앱이 자동으로 열립니다. 푸시 알림을 클릭하면됩니다.

답변

0

제거

startActivity(intentblank); 
0

알림 클릭시 로그인 활동을 항상 호출하십시오. 로그인 활동에서 사용자가 로그인했는지 여부를 점검하십시오. 주요 활동으로 이동 로그인에 다른 로그인 활동에

0

사용이있을 경우

 Intent loginIntent = new Intent(getApplicationContext(),LoginActivity.class); 
     loginIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
       | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, loginIntent ,PendingIntent.FLAG_UPDATE_CURRENT); 

를 넣어 로그인 체크를위한 당신의 상태 안에 startActivity(loginIntent);. 코드의 라인 아래