package com.example.notificationtest; import android.os.Bundle; 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.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; public class MainActivity extends Activity { NotificationManager notificationManager; Spinner spinner; String[] arr = { "请选择", "face", "folder", "other", "text", "why" }; ArrayAdapter<String> adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); spinner = (Spinner) findViewById(R.id.spinner); adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, arr); adapter.setDropDownViewResource(R.layout.text); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 1) { setNotifi(R.drawable.face, arr[1]); } if (position == 2) { setNotifi(R.drawable.folder, arr[2]); } if (position == 3) { setNotifi(R.drawable.other, arr[3]); } if (position == 4) { setNotifi(R.drawable.txt, arr[4]); } if (position == 5) { setNotifi(R.drawable.why, arr[5]); } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); } private void setNotifi(int id, String text) { Intent intent = new Intent(this, Test.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pend = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); Notification notification = new Notification(); notification.icon = id; notification.tickerText = text; notification.defaults = Notification.DEFAULT_SOUND; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(MainActivity.this, "MSN", text, pend); notificationManager.notify(0, notification); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
相关推荐
本实例描述的Android开发中的Notification通知控件的应用,包括通知的创建、属性设置、跳转方法以及删除等。希望能给学习Notification通知的朋友带来帮助。
Google Google.Android开发入门与实战第7章.良好的学习开端——Android基本组件介绍之温馨的提醒——Toast和Notification应用.rar
带声音的Notification、振动的Notification、声音 振动的Notification,最后清除Notification,看似简单的一些Notification应用,实际在日常编程中经常用到的。演示各个Notification及Toast的具体功能,请下载本源码...
此应用程序是Angular 5 Web应用程序中用于推送通知和实时通知处理的POC。 产品特点! 实时通知:在NodeJS Server和Angular 5 Application之间使用套接字连接。 推送通知:使用Google FCM在Chrome上注册应用程序的...
在消息通知时,我们经常用到两个组件Toast和Notification。特别是重要的和需要长时间显示的信息,用Notification就最合适不过了。当有消息通知时,状态栏会显示通知的图标和文字,通过下拉状态...
8.3 Toast和Notification应用 8.3.1 使用Notification通知 用户服务启动 8.3.2 使用Toast显示通知信息 8.4 应用实例详解:播放背景音乐 8.4.1 实例分析 8.4.2 实例实现 第9章 Android中的数据存储 9.1 使用...
android中Toast和Notification的应用.
7.8 温馨的提醒——Toast和Notification应用 7.8.1 实例操作演示 7.8.2 实例编程实现 7.9 本章小结 第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences...
7.8 温馨的提醒——Toast和Notification应用 7.8.1 实例操作演示 7.8.2 实例编程实现 7.9 本章小结 第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences...
7.8 温馨的提醒——toast和notification应用 127 7.8.1 实例操作演示 128 7.8.2 实例编程实现 129 7.9 本章小结 135 第8章 移动信息仓库——android的数据存储操作 136 8.1 android数据存储概述 ...
Android应用源码之notification.zip项目安卓应用源码下载Android应用源码之notification.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
这个例子演示Android 在状态栏添加Notification信息图标及提示,相信大家对这个功能已经不陌生了,手机中安装的APP,一般都会在后台运行,时不时会在手机顶部的状态栏中显示应用的图标,滑出状态栏会看到详细的信息...
第7章 良好的学习开端——Android基本组件介绍之温馨的提醒——Toast和Notification应用 第8章 移动信息仓库——Android的数据存储操作之Android数据存储概述 第8章 移动信息仓库——Android的数据存储操作之轻轻地...
7.8 温馨的提醒——Toast和Notification应用 7.8.1 实例操作演示 7.8.2 实例编程实现 7.9 本章小结 第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences...
7.8 温馨的提醒——Toast和Notification应用 127 7.8.1 实例操作演示 128 7.8.2 实例编程实现 129 7.9 本章小结 135 第8章 移动信息仓库——Android的数据存储操作 136 8.1 Android数据存储概述 ...
android 源码学习
Android应用源码之notification1.zip项目安卓应用源码下载Android应用源码之notification1.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
使用android做的小例子 可以在通知栏显示消息和小图标 点击进去可以进入一个页面 主要用于notification的学习 基于android2.3开发
ESB应用Hello_World_Notification