`
java-mans
  • 浏览: 11468106 次
文章分类
社区版块
存档分类
最新评论

Android Notification通知的运用

 
阅读更多

package gongzibai.co.cc;

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.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class EA2Activity extends Activity {

private NotificationManager mNotificationManager;
private Spinner mSpinner;
private ArrayAdapter<String> mAdapter;

private static final String[] status = {

"在线", "离开", "回家", };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mSpinner = (Spinner) findViewById(R.id.spinner1);
mAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, status);
mSpinner.setAdapter(mAdapter);
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub

if (status[arg2].equals("在线")) {
setNotiType(R.drawable.ic_launcher, "在线了");

} else if (status[arg2].equals("离开")) {
setNotiType(R.drawable.ic_launcher, "离开了");

} else if (status[arg2].equals("回家")) {
setNotiType(R.drawable.ic_launcher, "回家了");

}

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
});

}

private void setNotiType(int iconID, String string) {
// TODO Auto-generated method stub

PendingIntent intent = PendingIntent.getActivity(EA2Activity.this, 0,
new Intent(EA2Activity.this, EA2Activity.class), 0);

Notification mNotification = new Notification();

mNotification.tickerText = string;
mNotification.icon = iconID;
mNotification.defaults = Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE;
mNotification.setLatestEventInfo(EA2Activity.this, "登录状态", string,
intent);

mNotificationManager.notify(3, mNotification);

}
}

--------------------------

通知的应用一定要设置一个图片,否则通知在状态栏只有提示声音,没有文字的出现..

震动的通知,在权限增加震动权限.

分享到:
评论

相关推荐

    Android Notification通知解析

    Notification是显示在手机状态栏的通知,Notification通知是具有全局性的通知,一般通过NotificationManager来进行管理. 一般运用Notification的步骤如下: 1.调用getSysytemService(NOTIFICATION_SERVICE)来获取...

    android 插件plugin

    通知栏限制(无法在插件中发送具有自定义资源的Notification,例如: 1. 带自定义RemoteLayout的Notification 2. 图标通过R.drawable.XXX指定的通知(插件系统会自动将其转化为Bitmap) - b.安全性担忧(可以修改...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...

    下载apk-Android

    有2个下载案例 大家可酌情考虑运用...1. 服务1 okhttp + notification 通知栏带进度的下载apk 实现自动安装 点击通知栏安装 自定义通知栏样式 静默下载等 提供忽略当前版本 2. 服务2 运用downloadManager实现相同的效果

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...

    Google Android SDK开发范例大全的目录

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源...

    Android典型技术模块开发详解

    8.11 Notification(通知) 8.11.1 一般的Notification 8.11.2 带进度的Notification 8.12 Toast(提示) 8.13 本章小结 第9章 风格与动画 9.1 主题与风格 9.1.1 风格style 9.1.2 主题Theme 9.2 View的绘制 9.3 ...

    Google Android SDK 开发范例大全01

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...

    Google Android SDK 开发范例大全02

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...

    Google+Android+SDK开发范例大全

    Google服务与Android混搭 9.1 Google帐号验证Token——AuthSub 9.2 Google搜索——AutoCompleteTextView与GoogleSearchAPI 9.3 前端产生QRCode二维条形码——GoogleChartAPI 9.4 以经纬度查找目的地位置——GeoPoint...

    Google Android sdk 开发范例大全 部分章节代码

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...

    Google Android SDK开发范例大全(完整版)

    5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...

    安卓作业—-慕课移动应用开发作业19之自定义Notification布局

    本篇运用ImageView和TextView等对Notification进行自定义布局 同时这也是中国大学慕课移动终端应用开发的网课作业19,我会持续更新我的作业,如果有需要关注一下吧 说明 1.参考文章安卓仿网易云音乐通知栏控制音乐 2...

Global site tag (gtag.js) - Google Analytics