[英]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.