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);
}
}
--------------------------
通知的应用一定要设置一个图片,否则通知在状态栏只有提示声音,没有文字的出现..
震动的通知,在权限增加震动权限.
分享到:
相关推荐
Notification是显示在手机状态栏的通知,Notification通知是具有全局性的通知,一般通过NotificationManager来进行管理. 一般运用Notification的步骤如下: 1.调用getSysytemService(NOTIFICATION_SERVICE)来获取...
通知栏限制(无法在插件中发送具有自定义资源的Notification,例如: 1. 带自定义RemoteLayout的Notification 2. 图标通过R.drawable.XXX指定的通知(插件系统会自动将其转化为Bitmap) - b.安全性担忧(可以修改...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
有2个下载案例 大家可酌情考虑运用...1. 服务1 okhttp + notification 通知栏带进度的下载apk 实现自动安装 点击通知栏安装 自定义通知栏样式 静默下载等 提供忽略当前版本 2. 服务2 运用downloadManager实现相同的效果
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源...
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 ...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
Google服务与Android混搭 9.1 Google帐号验证Token——AuthSub 9.2 Google搜索——AutoCompleteTextView与GoogleSearchAPI 9.3 前端产生QRCode二维条形码——GoogleChartAPI 9.4 以经纬度查找目的地位置——GeoPoint...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
本篇运用ImageView和TextView等对Notification进行自定义布局 同时这也是中国大学慕课移动终端应用开发的网课作业19,我会持续更新我的作业,如果有需要关注一下吧 说明 1.参考文章安卓仿网易云音乐通知栏控制音乐 2...