2013-04-03 28 views
1

我的問題對你有以下幾點:我有一個用HTML5編寫的網絡應用程序,它被封裝爲原生Android應用程序以便使用Google推送通知。因爲我的應用程序出於不同的原因正在使用多個通知,所以我希望能夠在每次收到通知時說出要打開的頁面,例如在通知意圖中添加「href」。這可能嗎? 如果我不夠清楚,請讓我知道。 謝謝Android推送通知打開自定義頁面

回答

0

您可以定義自己的通知消息內容。來自Google的消息構建器支持由通知發件人設置的鍵值對。 見http://developer.android.com/reference/com/google/android/gcm/server/Message.html

例子:

Message message = new Message.Builder() 
    .addData("link1", "http://mypage1.com") 
    .addData("link2", "http://mypage2.com") 
    .build(); 
+0

我已經在使用這個,所以我可以知道每一個通知是什麼類型的。但是,一旦通知到達,我不知道如何打開我的應用程序的某個webview。我想有一些Intent對象,我仍在搜索。 – Alex

+0

您可以使用url啓動Android瀏覽器,也可以開始自己的包含webview的活動。 請參閱http://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application – userM1433372

0

當您創建的通知,請使用setContentIntent()附加已構建訪問權網頁的意圖:

// assuming <this> is an Activity or other Context 
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(yourUrl)); 
PendingIntent urlPendingIntent = PendingIntent.getActivity(this, 0 urlIntent, 0); 
Notification.Builder b = new Notification.Builder(this) 
    .setSmallIcon(...).setContentTitle(...).setContentText(...) // etc. 
    .setContentIntent(urlPendingIntent); 
NotificationManager noMan 
    = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
noMan.notify(ID, b.build()); 

如果你希望有在通知面板中一次多於一個:

  1. 重新考慮。這是垃圾郵件發佈多個通知。
  2. 如果必須,您需要爲每個ID分配一個單獨的ID(或單獨的標籤)。