您的位置:首页 > 移动开发

android app notification的用法

2015-06-19 11:19 363 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: