2013-09-29 27 views
2

請在下面找到具有存檔和回覆選項的android gmail通知畫面。 在按回復而不是打開gmail應用程序時,edittext應顯示在通知區域,該區域將接受回覆文本 消息和回覆消息應從通知本身發送。 我們如何實現這一目標? 根據下面的鏈接,我們可以顯示設置操作歸檔和回覆按鈕。 http://developer.android.com/training/notify-user/expanded.htmlenter image description here如何從android中的可擴展通知發送回覆?

// Sets up the archive and reply action buttons that will appear in the 
// big view of the notification. 

Intent archiveIntent = new Intent(this, ResultActivity.class); 
archiveIntent.setAction(CommonConstants.ACTION_ARCHIVE); 
PendingIntent piArchive = PendingIntent.getService(this, 0, archiveIntent, 0); 

Intent replyIntent = new Intent(this, ResultActivity.class); 
replyIntent.setAction(CommonConstants.ACTION_REPLY); 
PendingIntent piReply = PendingIntent.getService(this, 0, replyIntent, 0); 


NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
.setSmallIcon(R.drawable.ic_stat_notification) 
.setContentTitle(getString(R.string.notification)) .setContentText(getString(R.string.ping)) 
.setDefaults(Notification.DEFAULT_ALL) 
.setStyle(new NotificationCompat.BigTextStyle() 
.bigText(msg)) 
.addAction (R.drawable.ic_stat_archive,getString(R.string.archive), piArchive) 
.addAction (R.drawable.ic_stat_reply,getString(R.string.reply), piReply); 

在按下回覆按鈕,而不是去Gmail應用/打開整版ResultActivity 它應該顯示的EditText指定的高度,寬度和在通知區域本身一個答覆按鈕。 這是如何實現的? 請建議可以採用哪種方法來達到此目的。 在此先感謝。

+0

我希望回覆按鈕與Gmail應用相同,我希望我的活動能夠被打開。我用你的代碼。當我點擊回覆按鈕時,它不會打開我的活動。 「CommonConstants.ACTION_REPLY」的價值是什麼? – Bunny

回答

0

這是目前不可能的。您有一組可能的通知類型,如下所示:http://developer.android.com/guide/topics/ui/notifiers/notifications.html並且它們都不允許在通知抽屜中輸入。你可以做的第二件事是讓他們點擊回覆,只需要一個對話框就可以打開對話框(並且不打開整個活動)

+0

從下面的視頻中我看到twitter應用程序提供了我目前正在尋找的回覆功能。 http://www.youtube.com/watch?feature=player_embedded&v=dkTFv2V4lRo 但我想知道如何做到這一點。請看看,讓我們知道你是否有任何建議。 – user1537457

+1

@ user1537457正如您在視頻中注意到的那樣,通知抽屜會實際關閉並彈出一個新對話框,因此您不必在通知中創建它,而必須創建一個單獨的活動,並將其作爲一個對話框單擊在通知 –

+0

感謝您的答覆按鈕。我會盡力用對話做到這一點。 – user1537457