当前位置:编程学习 > wap >>

新手关于Notification的疑问

package com.example.ex05_2;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Ex05_2Activity extends Activity {
Button loginBtu, clearBtu;
NotificationManager m_NotificationManager;
Intent m_Intent;
PendingIntent m_PendingIntent;
//声明Notification对象
Notification m_Notification;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ex05_2);
        
        m_NotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

//获取4个按钮对象
loginBtu = (Button) findViewById(R.id.login);
clearBtu = (Button) findViewById(R.id.clear);

//点击通知时转移内容

loginBtu.setOnClickListener(new OnClickListener()
{

public void onClick(View v)
{
m_Intent = new Intent(Ex05_2Activity.this, Ex05_2Activity2.class);
//主要是设置点击通知时显示内容的类
m_PendingIntent = PendingIntent.getActivity(Ex05_2Activity.this, 0, m_Intent, 0);
//构造Notification对象
m_Notification = new Notification();
//当我们点击通知时显示的内容
m_Notification.tickerText = "Button1通知内容...........";

//设置通知显示的参数
m_Notification.setLatestEventInfo(Ex05_2Activity.this, "Button1", "Button1通知", m_PendingIntent);

m_NotificationManager.notify(0, m_Notification);
}
});
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_ex05_2, menu);
        return true;
    }
}


基本照书照抄的了,只是改了下变量,依旧不行?!
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,