<span style="font-size:18px;">public void showDialog()
{
Log.i(TAG, " matt-showDialog");
Notification notification = new Notification();
notification.icon = R.drawable.ic_launcher;
notification.when = System.currentTimeMillis();
if(notification==null)
Log.i(TAG, " matt-notification==null");
else{
String service = Context.NOTIFICATION_SERVICE;
mNotification = (NotificationManager)getSystemService(service);
String tickerText = "测试Notification";
notification.tickerText = tickerText;
notification.flags = Notification.FLAG_AUTO_CANCEL;
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.matt); //这里需要自己搞一个xml来显示图片
rv.setTextViewText(R.id.text_content, "hello wrold!");
notification.contentView = rv;
Intent intent = new Intent(Intent.ACTION_MAIN);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, intent, 1);
notification.contentIntent = contentIntent;
mNotification.notify(1, notification);
}
}</span>
接下来是matt.xml文件
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
</LinearLayout>
</span>