安卓:当新通知到达时显示/隐藏状态栏
问题描述:
我的应用程序应该以全屏模式运行。此外,当我的服务器上有新项目到达我的应用程序时,我还必须显示通知栏。我在BroadcastReceiver类中编写通知编码。我想在MainActivity中做出决定,例如只有在收到新通知时隐藏状态栏才显示状态栏。所有这些都是在应用程序处于前台时完成的。安卓:当新通知到达时显示/隐藏状态栏
编码通知:
Intent scheduledIntent = new Intent(context,Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, scheduledIntent, 0);
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "From address";
CharSequence message = "New Orders received";
Notification notif = new Notification(R.drawable.icon,"Hai", System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, pendingIntent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(uniqueID, notif);
notif.ledOnMS = 500;
notif.ledOffMS = 500;
通过这个代码通知收到。但状态栏始终可见。当收到通知时我需要隐藏。 请为我提供正确的方法。
由于提前,
答
In oncreate method u have write this one
AppPreferences prefs = new AppPreferences(PresentChatActivity.this);
boolean notify_checkbox = prefs.getNotifyState();
Notification(message.getBody(),fromName, name);
u have to create method:
protected void Notification(String body, String fromName, String Notificationmsg) {
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
String tickerText = getString(R.string.app_name, body);
Notification notif = new Notification(R.drawable.ic_launcher, tickerText,
System.currentTimeMillis());
Intent notificationIntent = new Intent(this, PresentChatActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notif.setLatestEventInfo(PresentChatActivity.this,Notificationmsg, message, pendingIntent);
notif.setLatestEventInfo(getApplicationContext(), fromName, body,pendingIntent);
notificationManager.notify(10001, notif);
}
我也面临着从过去的2天相同的概率,但最后我扶正这样的代码了吧.. – shassss
一次检查我的答案我已经编辑斯里达尔 – shassss
你长了输出 – shassss