首页 > 其他 > 详细

兔子--Notification的使用

时间:2014-11-23 11:47:50      阅读:223      评论:0      收藏:0      [点我收藏+]
<span style="font-size:18px;color:#ff0000;">
</span>
<span style="font-size:18px;color:#ff0000;">使用步骤:
</span><p><span style="font-size:18px;color:#ff0000;">1 获取通知管理器NotificationManager,它也是一个系统服务</span></p><p><span style="font-size:18px;color:#ff0000;">
</span></p><p><span style="font-size:18px;color:#ff0000;">2 建立通知Notification notification = new Notification(icon, null, when);</span></p><p><span style="font-size:18px;color:#ff0000;">
</span></p><p><span style="font-size:18px;color:#ff0000;">3 为新通知设置参数(比如声音,震动,灯光闪烁)</span></p><p><span style="font-size:18px;color:#ff0000;">
</span></p><p><span style="font-size:18px;color:#ff0000;">4 把新通知添加到通知管理器</span></p><div><span style="font-size:18px;color:#ff0000;">
</span></div><span style="font-size:18px;color:#ff0000;">
</span>
<span style="font-size:18px;color:#330000;">
</span>
<span style="font-size:18px;color:#330000;">
</span>
<span style="font-size:18px;color:#330000;">
</span>
<span style="font-size:18px;color:#330000;">package com.example.mynotification;

import android.app.Activity;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Context;
import android.content.Intent;

import android.os.Bundle;

import android.text.NoCopySpan.Concrete;
import android.view.View;

import android.widget.Button;

import android.widget.TextView;

public class MainActivity extends Activity {

	Button m_Button1;

	TextView m_txtView;

	NotificationManager mNotificationManager;

	Notification mNotification;

	Intent mIntent;

	PendingIntent mPendingIntent;
	Context context;

	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);
		context = this;
		final Notification notification;
		mNotificationManager = (NotificationManager) this
				.getSystemService(NOTIFICATION_SERVICE);

		m_Button1 = (Button) this.findViewById(R.id.button1);

		// 点击通知时转移内容

		mIntent = new Intent(MainActivity.this, MainActivity1.class);

		mPendingIntent = PendingIntent.getActivity(MainActivity.this, 0,
				mIntent, 0);

		notification = new Notification.Builder(context).setAutoCancel(true)
				.setContentTitle("qq正在运行").setContentText("qq,让交流更多方便")
				.setContentIntent(mPendingIntent)
				.setSmallIcon(R.drawable.ic_launcher)
				.setWhen(System.currentTimeMillis()).build();

		m_Button1.setOnClickListener(new Button.OnClickListener() {

			public void onClick(View v) {

				mNotificationManager.notify(0, notification);

			}
		});

	}
}
</span>






兔子--Notification的使用

原文:http://blog.csdn.net/u013425527/article/details/41408723

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!