RemoteViews remoteview = new第1引数にはパッケージ名を指定します。これは、このActivityクラスのgetPackageNameメソッドを呼び出し取得すればいいでしょうそして第2引数にはレイアウト用のリソースIDを指定します。あらかじめ、ノーティフィケーションで表示するレイアウトをXMLファイルとして用意しておき、ここにそのIDを設定します。
RemoteViews(パッケージ名, リソースID );
【Notification】.contentView =【RemoteView】;ただし、これだけではうまくいきません。RemoteViewを独自に追加する場合、Notificationの「setLatestEventInfo」は使えなくなります。したがって、PendingIntentを別のやり方で設定してやる必要があるのです。
【Notification】.contentIntent =【PendingIntent】;これでOKです。下のリスト欄に独自の表示を行うノーティフィケーションの例を挙げておきました。ここでは、item.xmlというファイルを作成してレイアウトを用意し、これを利用することにしています。実際にitem.xmlにレイアウトを配置して試してみましょう。オリジナルの表示ができるというのは、なかなか面白いですよ!
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※item.xmlのソースコード <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1"> <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/textView1" android:layout_weight="0.03" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="サンプルで作ったView" android:background="#66CC00"></TextView> </LinearLayout> ※オリジナルの表示を行う public void doAction(View view){ RemoteViews remoteview = new RemoteViews(this.getPackageName(), R.layout.item); Intent intent = new Intent(this,jp.tuyano.sample.MySampleActivity.class); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notify = new Notification(); notify.contentView = remoteview; notify.flags = Notification.FLAG_AUTO_CANCEL; notify.icon = R.drawable.icon; notify.contentIntent = pending; NotificationManager manager = (NotificationManager)this. getSystemService(Activity.NOTIFICATION_SERVICE); manager.notify(0, notify); }
<< 前へ |