package com.szy.statusbar;
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.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RemoteViews;
public class MainActivity extends Activity
{
private Button btnBar;
private Button btnCancel;
private Button btnUpdate;
private Button btnCustom;
private static final int STATUS_BAR_ID = 1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnBar=(Button)findViewById(R.id.btnBar);
btnBar.setOnClickListener(listener);
btnCancel=(Button)findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(listener);
btnUpdate=(Button)findViewById(R.id.btnUpdate);
btnUpdate.setOnClickListener(listener);
btnCustom=(Button)findViewById(R.id.btnCustom);
btnCustom.setOnClickListener(listener);
}
private OnClickListener listener = new OnClickListener()
{
@Override
public void onClick(View v)
{
NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification;
Context context;
CharSequence contentTitle;
CharSequence contentText;
Intent intent;
PendingIntent contentIntent;
switch (v.getId())
{
case R.id.btnBar:
notification = new Notification();
notification.icon=R.drawable.bar;
notification.tickerText="Android开发从零开始";
notification.when=System.currentTimeMillis();
//notification.flags=Notification.FLAG_AUTO_CANCEL;
context = getApplicationContext();
contentTitle = "通知";
contentText = "大家好,Android开发从零开始又开始录制了。";
intent = new Intent(MainActivity.this, StatusBarActivity.class);
contentIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notificationManager.notify(STATUS_BAR_ID, notification);
break;
case R.id.btnCancel:
notificationManager.cancel(STATUS_BAR_ID);
break;
case R.id.btnUpdate:
notification = new Notification();
notification.icon=R.drawable.bar;
notification.tickerText="第二条消息";
notification.when=System.currentTimeMillis();
context = getApplicationContext();
contentTitle = "通知";
contentText = "两条消息未读。";
intent = new Intent(MainActivity.this, StatusBarActivity.class);
contentIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notificationManager.notify(STATUS_BAR_ID, notification);
break;
case R.id.btnCustom:
notification = new Notification();
notification.icon=R.drawable.bar;
notification.tickerText="Android开发从零开始";
notification.when=System.currentTimeMillis();
notification.flags=Notification.FLAG_AUTO_CANCEL;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.image, R.drawable.notification_image);
contentView.setTextViewText(R.id.text, "自定义显示界面");
notification.contentView = contentView;
intent = new Intent(MainActivity.this, StatusBarActivity.class);
contentIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
notification.contentIntent = contentIntent;
notificationManager.notify(STATUS_BAR_ID, notification);
break;
default:
break;
}
}
};
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android应用源码之40.Status_Bar_Notifications.zip项目安卓应用源码下载
共30个文件
class:9个
xml:5个
java:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 105 浏览量
2022-03-07
20:14:20
上传
评论
收藏 207KB ZIP 举报
温馨提示
Android应用源码之40.Status_Bar_Notifications.zip项目安卓应用源码下载Android应用源码之40.Status_Bar_Notifications.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码之40.Status_Bar_Notifications.zip (30个子文件)
Android应用源码之40.Status_Bar_Notifications
Android应用源码之40.Status_Bar_Notifications
40.Status Bar Notifications
src
35.StatusBar
AndroidManifest.xml 807B
res
layout
custom_notification_layout.xml 699B
statusbar.xml 376B
main.xml 864B
drawable-ldpi
icon.png 2KB
drawable-mdpi
notification_image.jpg 1KB
bar.gif 1KB
icon.png 3KB
drawable-hdpi
icon.png 4KB
values
strings.xml 172B
proguard.cfg 1KB
src
com
szy
statusbar
MainActivity.java 4KB
StatusBarActivity.java 277B
bin
com
szy
statusbar
MainActivity$1.class 3KB
R.class 524B
MainActivity.class 1KB
R$layout.class 474B
R$attr.class 337B
R$id.class 537B
StatusBarActivity.class 530B
R$string.class 424B
R$drawable.class 466B
classes.dex 5KB
35.StatusBar.apk 19KB
resources.ap_ 15KB
.classpath 280B
assets
default.properties 362B
.project 848B
gen
com
szy
statusbar
R.java 1KB
doc
40.Status Bar Notifications.ppt 229KB
video
共 30 条
- 1
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功