2013-07-15 21 views
0

我正在將Urban Airship推送通知添加到我的Android應用。我發送測試推送時,我的自定義BroadcastReceiver正在接收通知。這是onReceive()方法。收到通知但未顯示

public class IntentReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     if(intent == null) 
      return; 

    String action = intent.getAction(); 

    if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) { 
     int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0); //Breakpoint here 

     Log.w("my app", "Received push notification. Alert: " 
       + intent.getStringExtra(PushManager.EXTRA_ALERT) 
       + " [NotificationID="+id+"]"); 

     logPushExtras(intent); 

    } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) { 
     //Other stuff here 
    } 

執行停止在斷點(註釋中顯示的位置)並記錄詳細信息。

儘管通知區域中未顯示通知。在我用UA推送通知的其他應用程序中,我認爲這就是我所做的,但這次似乎沒有工作。

我懷疑我在我的清單文件中做了一些錯誤,或者我忘記了在某個地方實現一個類。

任何想法?

額外的資訊

擴展應用:

public class ExtendedApplication extends Application { 

    public void onCreate(){ 
     AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this); 
     UAirship.takeOff(this, options); 
     PushManager.enablePush(); 

     PushPreferences prefs = PushManager.shared().getPreferences(); 
     Log.e("my app", "My Application onCreate - App APID: " + prefs.getPushId()); 

     PushManager.shared().setIntentReceiver(IntentReceiver.class); 
    } 
} 

編輯

我已經嘗試添加

PushManager.shared().setNotificationBuilder(new BasicPushNotificationBuilder()); 

我ExtendedApplication一個s在this後建議。

回答

0

我正在從UA站點發送帶有空白「警報」字段的測試推送。我嘗試了一些文本,現在它工作。我不知道爲什麼,但我不認爲這是應該默默地失敗的。

道德故事:不要將警報區域留空。