package src.com;
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.View;
import android.widget.Button;
public class Activity01 extends Activity
{
Button m_Button1, m_Button2, m_Button3, m_Button4;
//声明通知(消息)管理器
NotificationManager m_NotificationManager;
Intent m_Intent;
PendingIntent m_PendingIntent;
//声明Notification对象
Notification m_Notification;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//初始化NotificationManager对象
m_NotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//获取4个按钮对象
m_Button1 = (Button) findViewById(R.id.Button01);
m_Button2 = (Button) findViewById(R.id.Button02);
m_Button3 = (Button) findViewById(R.id.Button03);
m_Button4 = (Button) findViewById(R.id.Button04);
//点击通知时转移内容
m_Intent = new Intent(Activity01.this, Activity02.class);
//主要是设置点击通知时显示内容的类
m_PendingIntent = PendingIntent.getActivity(Activity01.this, 0, m_Intent, 0);
//构造Notification对象
m_Notification = new Notification();
m_Button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
//设置通知在状态栏显示的图标
m_Notification.icon = R.drawable.img1;
//当我们点击通知时显示的内容
m_Notification.tickerText = "Button1通知内容...........";
//通知时发出默认的声音
m_Notification.defaults = Notification.DEFAULT_SOUND;
//设置通知显示的参数
m_Notification.setLatestEventInfo(Activity01.this, "Button1", "Button1通知", m_PendingIntent);
//可以理解为执行这个通知
m_NotificationManager.notify(0, m_Notification);
}
});
m_Button2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
m_Notification.icon = R.drawable.img2;
m_Notification.tickerText = "Button2通知内容...........";
//通知时震动
m_Notification.defaults = Notification.DEFAULT_VIBRATE;
m_Notification.setLatestEventInfo(Activity01.this, "Button2", "Button2通知", m_PendingIntent);
m_NotificationManager.notify(0, m_Notification);
}
});
m_Button3.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
m_Notification.icon = R.drawable.img3;
m_Notification.tickerText = "Button3通知内容...........";
//通知时屏幕发亮
m_Notification.defaults = Notification.DEFAULT_LIGHTS;
m_Notification.setLatestEventInfo(Activity01.this, "Button3", "Button3通知", m_PendingIntent);
m_NotificationManager.notify(0, m_Notification);
}
});
m_Button4.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
m_Notification.icon = R.drawable.img4;
m_Notification.tickerText = "Button4通知内容..........";
//通知时既震动又屏幕发亮还有默认的声音
m_Notification.defaults = Notification.DEFAULT_ALL;
m_Notification.setLatestEventInfo(Activity01.this, "Button4", "Button4通知", m_PendingIntent);
m_NotificationManager.notify(0, m_Notification);
}
});
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
2种源码(显示进度条).zip (56个子文件)
Test_1
AndroidManifest.xml 672B
res
layout
main.xml 744B
drawable-ldpi
img2.jpg 64KB
img1.jpg 64KB
img3.jpg 64KB
img4.jpg 64KB
icon.png 2KB
drawable-mdpi
icon.png 3KB
drawable-hdpi
icon.png 4KB
values
strings.xml 176B
src
src
com
Activity01.java 5KB
Activity02.java 52B
bin
src
com
Activity01$1.class 1KB
Activity01$3.class 1KB
R.class 454B
Activity02.class 271B
R$layout.class 361B
R$attr.class 307B
R$id.class 449B
R$string.class 394B
Activity01.class 2KB
R$drawable.class 479B
Activity01$2.class 1KB
Activity01$4.class 1KB
Test_1.apk 273KB
classes.dex 5KB
resources.ap_ 269KB
.classpath 280B
assets
default.properties 364B
.project 842B
gen
src
com
R.java 1KB
Test_2
AndroidManifest.xml 670B
res
layout
notification.xml 809B
main.xml 607B
drawable-ldpi
icon.png 2KB
drawable-mdpi
icon.png 3KB
drawable-hdpi
icon.png 4KB
values
strings.xml 173B
src
src
wcg
com
main.java 3KB
bin
src
wcg
com
main$2.class 1KB
main$3.class 812B
R.class 482B
main.class 3KB
R$layout.class 409B
R$attr.class 319B
main$1.class 856B
R$id.class 444B
R$string.class 406B
R$drawable.class 379B
classes.dex 5KB
Test_2.apk 16KB
resources.ap_ 11KB
.classpath 280B
assets
default.properties 364B
.project 842B
gen
src
wcg
com
R.java 933B
共 56 条
- 1
磊哥降临
- 粉丝: 0
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页