0

我的應用程序應該以全屏模式運行。此外,當我的服務器上有新項目到達我的應用程序時,我還必須顯示通知欄。我在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; 

通過這個代碼通知收到。但狀態欄始終可見。當收到通知時我需要隱藏。 請爲我提供正確的方法。

由於提前,

+0

我也面臨着從過去的2天相同的概率,但最後我扶正這樣的代碼了吧.. – shassss

+0

一次檢查我的答案我已經編輯斯里達爾 – shassss

+0

你長了輸出 – shassss

回答

0
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); 
    } 
+0

什麼是notify_checkbox和chat_data – Sridhar

+0

它的一切,但我們通知複選框然後ckeck框只檢查通知wil顯示,否則通知將不會顯示 – shassss

+0

在你的程序無需檢查和未檢查意味着你可以直接添加像這樣Notification(message.getBody (),fromName,name); – shassss