简体   繁体   English

收到推送通知时打开Android应用

[英]Open Android App when Push Notification is received

When a notification is received my android app opens up when the notification is clicked from notification center but along with that I want to open up my sliding drawer also.. Here is my code 当收到通知时,从通知中心单击通知时我的android应用程序打开,但与此同时我也想打开滑动抽屉。这是我的代码

IntentReceiver.class (custom push receiver) IntentReceiver.class(自定义推送接收器)

     String action = intent.getAction();
    if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {
          Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));

        //  logPushExtras(intent);
          if(!MainActivity.active){
          Intent launch = new Intent(Intent.ACTION_MAIN);
          launch.setClass(UAirship.shared().getApplicationContext(), MainActivity.class);
          launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          UAirship.shared().getApplicationContext().startActivity(launch);
          }

  }
}

and this is in main activity.. 这是主要活动。

public static boolean active;

I want to add the following 我要添加以下内容

 final SlidingDrawer banner = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
        banner.animateOpen();

Can anyone tell me how to do it.. Open up sliding drawer when app is opened through notification. 谁能告诉我该怎么做。通过通知打开应用时,打开滑动抽屉。

Your question is a little unclear. 您的问题还不清楚。 As I understand it, you have a main activity that can be opened either from the launcher, or from a notification intent. 据我了解,您有一个主要活动,可以从启动器或通知意图中打开它。 You wish to open the Sliding Drawer only when the activity is started by a notification intent, but not when it is started from the launcher. 您希望在通过通知意图启动活动时才打开“滑动抽屉”,而不是从启动器中启动时才打开。 If that is the case, you merely need to use Intent.putExtra() when creating your launch intent, then check for the extra when your activity opens. 如果是这种情况,则只需在创建launch意图时使用Intent.putExtra() ,然后在活动打开时检查其他内容。

Add to IntentReceiver.class , before startActivity(launch) : startActivity(launch)之前添加到IntentReceiver.class

launch.putExtra("notification", "true");

In Main Activity : Main Activity

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yourlayoutfile);

    final SlidingDrawer banner = (SlidingDrawer) findViewById(R.id.slidingDrawer1);

    Intent intent = getIntent();
    String extra = intent.getStringExtra("notification");

    if(extra != null && extra.equals("true") && (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0)
    {
        banner.animateOpen();
    }
}

The FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY check is to ensure that the intent is coming from your receiver, and is not the Recent cached intent. FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY检查是为了确保该意图来自您的接收者,而不是最近缓存的意图。

Just as an FYI, SlidingDrawer has been deprecated. 与FYI一样,SlidingDrawer也已弃用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打开应用程序后未收到Android上的推送通知 - Push notification on Android doesn't received when app is open 收到推送通知时自动在Android上打开供应商应用程序(自动“按下”通知) - Open vendor app's on Android when push notifications are received (automatically 'press' notification) Firebase 在 android 中从后台删除应用程序时未收到推送通知 - Firebase push notification not received when app remove from background in android 当设备收到GCM推送通知时,会弹出Android应用程序 - Android app pop up when a GCM push notification is received on the device 应用程序被终止时,设备未收到推送通知 - push notification not received to devices when app is killed 收到推送通知时无需单击推送即可打开Android活动 - Android activity open while push notification is received without clicking on push 在Android中未收到推送通知 - Push Notification not Received in android 单击Azure Reach推送通知时打开android应用 - Open android app when clicking in an Azure Reach push notification 无法“打开”应用在后台时收到的通知 - Cannot "open" notification that is received when the app is in background 应用程序在前台时收到的推送通知与应用程序在后台时收到的推送通知不同 - Push notification received while the app is in the foreground is different from push notification received when the app is in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM