2012-09-05 6 views
6

にremoteviewsするのonclickリスナーを追加することが可能です私は、通知方法を作成しました:はアンドロイド

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    Notification notification; 

     notification = new Notification(R.drawable.messageicon, "You have a new message", 
       System.currentTimeMillis()); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 

     RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); 
     view.setImageViewResource(R.id.image, R.drawable.ic_launcher); 
     view.setTextViewText(R.id.title, "New Message"); 
     view.setTextViewText(R.id.text, message); 
     notification.contentView = view; 
     Intent intent = new Intent(); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     PendingIntent activity = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 
     notification.contentIntent = activity; 
     notificationManager.notify(0, notification); 

私がステータスバーに、ボタン、ポップアップのクリック時にボタンを追加したいです表示する必要があります。 ご協力いただければ幸いです。

+2

http://developer.android.com/reference/android/widget/RemoteViews.htmlメソッドはsetOnClickPendingIntentです。 – njzk2

答えて

11

直接行うことはできませんが、RemoteViews.setOnClickPendingIntent(int viewId、PendingIntent pendingIntent)を使用できます。

すべてのボタンonClickイベントで同じアクティビティを呼び出す場合は、Intent.setAction(Stringアクション)を異なる文字列で追加して、すべてのインテントをすべてのボタンに対して1つだけマージしないようにしてください。

あなたのアクティビティをテーマとしてテーマを設定すると、ポップアップが表示されます。

+1

主に、Intent.setAction(Stringアクション)について説明していただきありがとうございます! – Michal

+0

コードによるヘルプ:-) – Gattsu