-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);你的条件登录检查里面。

相关问题