- 浏览: 284891 次
- 性别:
- 来自: 北京
最新评论
-
肆无忌惮_:
多谢楼主分享
android内存泄露优化总结 -
wwwjiandan:
我用自定义Action为什么每次调用Activity时都提示找 ...
Activity之间的通信与自定义Action -
Zero颴:
写得好
android内存泄露优化总结 -
pigeon200461:
你好!请问你的这个项目里面是否使用sqlite3数据库。
android通过webview+jquery设计界面 -
ZHxin:
在activity中引入Fragment的xml方式确信能在低 ...
通过Compatibility Package低版本使用Fragment
代码:
package com.my;
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.provider.ContactsContract.CommonDataKinds.Note;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RemoteViews;
import android.widget.RemoteViews.RemoteView;
import android.widget.TextView;
public class NotificationActivity extends Activity implements OnClickListener {
private Button btnNotify_all;
private Button btnNotify_lights;
private Button btnNotify_sound;
private Button btnNotify_vibrate;
private Button btnCancelAll;
private Button btnCustomview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.tv);
textView.setText("Buhh");
btnNotify_all = (Button)findViewById(R.id.btnNotify_all);
btnNotify_all.setOnClickListener(this);
btnNotify_lights = (Button)findViewById(R.id.btnNotify_lights);
btnNotify_lights.setOnClickListener(this);
btnNotify_sound = (Button)findViewById(R.id.btnNotify_sound);
btnNotify_sound.setOnClickListener(this);
btnNotify_vibrate = (Button)findViewById(R.id.btnNotify_vibrate);
btnNotify_vibrate.setOnClickListener(this);
btnCancelAll = (Button)findViewById(R.id.btnCancelAll);
btnCancelAll.setOnClickListener(this);
btnCustomview = (Button)findViewById(R.id.btnCustomView);
btnCustomview.setOnClickListener(this);
}
private void showSimple(int id) {
// 第一步
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// 第二步
Notification notification = new Notification(R.drawable.icon, "new message",
System.currentTimeMillis());
notification.defaults = id;
// 第三步
Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
// 第四步
notification.setLatestEventInfo(this, "message", "hellow", pendingIntent);
// 第五步
notificationManager.notify(R.layout.main, notification);
}
private void showLedLight() {
// 第一步
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// 第二步
Notification notification = new Notification(R.drawable.icon, "new message",
System.currentTimeMillis());
// notification.defaults = Notification.DEFAULT_LIGHTS;
notification.ledARGB = 0xffffff;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
// 第三步
Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
// 第四步
notification.setLatestEventInfo(this, "message", "hellow", pendingIntent);
// 第五步
notificationManager.notify(R.layout.main, notification);
}
private void cancelAll() {
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
manager.cancelAll();
}
private void customView() {
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "new message",
System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.mynotificationview);
contentView.setImageViewResource(R.id.ivShow, R.drawable.icon);
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, NotificationActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notificationManager.notify(0, notification);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnNotify_all:
showSimple(Notification.DEFAULT_ALL);
break;
case R.id.btnNotify_lights:
showLedLight();
break;
case R.id.btnNotify_sound:
showSimple(Notification.DEFAULT_SOUND);
break;
case R.id.btnNotify_vibrate:
showSimple(Notification.DEFAULT_VIBRATE);
break;
case R.id.btnCustomView:
customView();
break;
case R.id.btnCancelAll:
cancelAll();
break;
default:
break;
}
}
}
发表评论
-
android内存泄露优化总结
2012-03-25 12:50 28099android手机给应用分配的 ... -
Android Market 链接的生成与分享
2012-02-21 11:59 5127通过Java包名直接定位到 ... -
android 事件处理过程
2011-12-16 14:37 1123转自:http://blog.sina.com.c ... -
【转】设置android程序平板下全屏
2011-12-13 11:11 3086【转自】http://blog.csdn.net/huoshe ... -
android 图片处理
2011-11-24 10:11 3235多张图片四个方位的图片合成,改变bitmap大小,图片去色等功 ... -
android 手机指令大全
2011-11-23 17:59 1*#*#4636#*#* 显示手机信息、电池信息、电池记录 ... -
Android-Activity Task 与 Intent Filter Flag
2011-11-17 10:47 4440接触 Android 以来,一直 ... -
ListView加载原理
2011-10-20 10:52 1310http://www.cnblogs.com/xiaowenj ... -
【转】SoftReference 和 WeakReference
2011-10-10 10:45 1563Java 和 Android 内存优化的两个类:SoftRef ... -
android异常处理发送消息给服务器
2011-10-08 18:45 3184转自:http://www.cnblogs.com/st ... -
通过Compatibility Package低版本使用Fragment
2011-09-26 16:47 4614android 3.0有很多新特性 其中有Fragmen ... -
PopupWindow+listItem 泡泡效果
2011-09-21 15:48 3938package com.my; import androi ... -
ViewSwitcher,ImageSwitcher,TextSwitcher的使用
2011-09-19 14:45 3211ImageSwitcher用于图片的切换动画效果 TextS ... -
requestWindowFeature使用详解
2011-09-19 10:41 100157requestWindowFeature可以设置的值有: / ... -
ViewSwitcher的使用
2011-09-16 10:17 4576[Android]ViewSwitcher使用范例 作 ... -
通过createPackageContext 实现皮肤打包成apk的demo
2011-09-14 16:56 4776通过Context friendContext = ... -
android selector使用
2011-08-30 10:10 3306转自:http://blog.sina.com ... -
android shape的使用
2011-08-30 10:07 1158转自:http://dev.10086.cn/cmdn/wi ... -
android迅雷下载搭建开发环境
2011-07-13 10:57 2169附件中有图片 转自: ... -
android四种补间动画
2011-07-12 12:24 7971android的动画分为两大类:补间动画,帧动画。 补间动画 ...
相关推荐
iphone notification 使用实例,简要的阐明了notification使用的方法,需要的可以下一下
Android NOtification 使用Android NOtification 使用
Notification 使用详解(很全)Notification 使用详解(很全)
本文实例讲解了通知Notification使用方法,此知识点就是用作通知的显示,包括振动、灯光、声音等效果,分享给大家供大家参考,具体内容如下 效果图: MainActivity: import java.io.File; import android....
使用android做的小例子 可以在通知栏显示消息和小图标 点击进去可以进入一个页面 主要用于notification的学习 基于android2.3开发
通知的使用大全,自定义等多方面的通知样式
在消息通知时,我们经常用到两个组件Toast和Notification。特别是重要的和需要长时间显示的信息,用Notification就最合适不过了。当有消息通知时,状态栏会显示通知的图标和文字,通过下拉状态...
Push Notification,为了是手机应用 keep onlive ,经常会有一个一直运转的后台服务程序,这样的应用使手机特别耗电,现在用了 Push Notification 可以来处理这个问题。
Android Notification使用详解 Notification 核心代码(链式调用):适用于Android 4.0以上(不兼容低版本) Notification noti = new Notification.Builder(this) .setContentTitle(标题名称) .setContentText...
主要介绍了Android Notification 使用方法详解的相关资料,这里提供实例来帮助大家理解掌握这部分内容,需要的朋友可以参考下
讲述关于notification的全面使用指南,通俗易懂的资料,适合新手
主要介绍了Android Notification使用方法总结的相关资料,这里提供了四种使用方法,需要的朋友可以参考下
如果您不会使用,请查看《WordPress Comment Reply Notification 使用教程》。 Plugin Name: Comment Reply Notification Plugin URI: ...
@ dafcoe / vue-notification 使用Vue3构建的易于使用,可自定义的通知/吐司库。 在页面上查看操作。安装使用yarn或npm将软件包安装为项目依赖项: $ yarn add @dafcoe/vue-notification--- or ---$ npm install --...
Notification的使用示例各种效果,包含系统一般notification的示例,以及自定义铃声震动等
一个关于安卓toast和notification使用方法的Android源码,来自eoeandroid社区,对初学者或许是个帮助吧。