私は現在Androidの通知を調べています。アプリケーションからのすべての通知を、Androidの通知ウィンドウに番号付きの単一の通知として表示する方法はありますか?これをクリックすると、ユーザーは個別の通知を含むアプリケーションのビューにリダイレクトされます。また、クリックされた通知に基づいてユーザーが適切なアクティビティにリダイレクトされるように、各通知のアクティビティを設定する方法はありますか。
2871 次
1 に答える
6
カウンターを含むカスタム レイアウトを notificationに添付できます。イベントが発生すると、カウンターが増加し、通知が更新されます。以下の例のように似ています:
Notification notification = new Notification(R.drawable.logo, name, System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(appContext.getPackageName(), R.layout.custom_layout );
contentView.setTextViewText(R.id.notification_text, Counter);
notification.contentView = contentView;
アクティビティを通知に添付するには:
Intent notificationIntent = new Intent(appContext, MyActivity.class);
Bundle bundle = new Bundle();
bundle.putInt(...);
notificationIntent.putExtras( bundle );
notificationIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
PendingIntent contentIntent = PendingIntent.getActivity( appContext, (int)System.currentTimeMillis(), notificationIntent, 0 );
notification.contentIntent = contentIntent;
それが役立つことを願っています。
于 2011-03-14T09:51:35.583 に答える