android之状态栏提示
来源:互联网 发布:软件漏洞扫描工具 编辑:程序博客网 时间:2024/04/29 11:07
android平台专门提供饿了NotificationManager来管理状态栏信息,提供Notification来处理这些信息。
首先通过getSystemService方法得到NotificationManager对象;
然后通过notify方法来执行一个Motification快讯。
下面是一个demo:
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.view.View.OnClickListener;
import android.widget.Button;
public class NotificationActivity extends Activity {
/** Called when the activity is first created. */
private Button m_Button1;
// 声明通知管理器
private NotificationManager notificationManager = null;
private Intent intent = null;
private PendingIntent pendingIntent = null;
// 声明Notification对象
private Notification notification = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 初始化NotificationManager对象
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// 获得Button
m_Button1 = (Button) findViewById(R.id.button1);
// 点击通知时转移内容
intent = new Intent(getApplicationContext(), Activity02.class);
// 主要设置点击通知的时显示内容的类
pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
intent, 0);
// 构造Notification对象
notification = new Notification();
m_Button1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// 设置通知在状态栏显示的图标
notification.icon = R.drawable.ic_launcher;
// 当我们点击通知时显示的内容
notification.tickerText = "Button1通知内容。。";
// 通知时发出的声音
notification.defaults = Notification.DEFAULT_SOUND;
// 设置同时显示的参数
notification.setLatestEventInfo(getApplicationContext(),
"Button1", "Button01的通知", pendingIntent);
// 可以理解为执行这个通知
notificationManager.notify(0, notification);
}
});
}
}
main.xml就不用写了!很简单。就是一个button和一个TextView
main2.xml中只有一个TextView用来显示一段string
所以Activity2中只有一个TextView
功能说明:点击NotificationActivity 中的Notification之后跳转到Activity2中,并显示main2中的内容。
不要忘了在AndroidManifest中注册Activity2
来源:http://blog.csdn.net/crazy1235/article/details/7268840
- android之状态栏提示
- android之状态栏提示
- Android--响铃、震动、状态栏提示
- Android 沉浸式状态栏之---纯色状态栏
- win32api之修改revit状态栏提示
- Android 状态栏提示的另一种方法
- Android通知之状态栏通知
- Android 自动更新之状态栏下载
- Android之设置状态栏颜色
- Android之隐藏标题栏、状态栏
- Android之沉浸式状态栏
- android 状态栏操作之-改变状态栏的颜色
- Android 应用开发笔记 - 状态栏提示(Notification、NotificationManager)
- 我的Android心得(5)--响铃、震动、状态栏提示
- 我的Android心得(5)--响铃、震动、状态栏提示
- android开发之向状态栏发送通知
- Android用户界面之notifaction(状态栏通知)
- Android 沉淀之标题、状态栏的隐藏
- 用Mysql存储过程迁移数据
- Android 状态栏通知Notification
- Top 10 Most Useful iOS Libraries to Know and Love
- 在 Android 中使用各种控件(View)
- C# Parameter使用like
- android之状态栏提示
- PDP相关
- 儿时的梦想您实现了吗?——《与时间同行》(8)
- grep学习笔记
- amlogic 8726 M6(无显示屏版本)编译
- UVa 10254 - The Priest Mathematician (4柱汉诺塔)
- 解决Failed to add the host to the list of known hosts
- Spring中PropertyPlaceholderConfigurer的使用
- 类 - 2【C++ Primer 学习笔记 - 第十二章】