android的notification的写法
来源:互联网 发布:java 防止 sql注入 编辑:程序博客网 时间:2024/05/29 07:05
这样来写:
public void onCreate() {super.onCreate();ntfmngr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);setNotifyType(R.drawable.logo,"aaaaaaaaaaa",3);}private void setNotifyType(int icon, String text, int num) {Intent notifyIntent = new Intent().setClass(getApplicationContext(),MainActivity.class);// notifyIntent.putExtra("mode", mNotifyMode);notifyIntent.setAction(Constants.UPDATE_HOME_LIST); //根据这个收到的activity可以接受这个action,判断是什么类型的消息// notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |// Intent.FLAG_ACTIVITY_NEW_TASK);PendingIntent appIntent = PendingIntent.getActivity(this, 0,notifyIntent, 0);Notification myNotification = new Notification();// myNotification.defaults = Notification.DEFAULT_VIBRATE;Uri soundUri = Uri.parse("android.resource://com.sina.weibo/raw/notificationsound");// Log.e(Constants.TAG, soundUri.getPath());myNotification.flags = Notification.FLAG_AUTO_CANCEL;myNotification.icon = icon;<strong>myNotification.defaults = Notification.DEFAULT_SOUND;myNotification.sound = soundUri; //notication过来的时候有声音</strong>if (num != -1) {myNotification.number = num;}long[] vb = new long[] { 80, 80 };myNotification.vibrate = vb;myNotification.tickerText = text;myNotification.setLatestEventInfo(this, getString(R.string.app_name),text, appIntent);System.out.println("====ntfmngr.notify");<strong>ntfmngr.notify(NOTIFY_MESSAGE, myNotification); </strong><pre name="code" class="java"><strong>//NOTIFY_MESSAGE为notification的key,可以根据key来取消</strong>}
必须加入相应的权限才有震动
<uses-permission android:name="android.permission.VIBRATE" />
可以这样来取消notication:
if (ntfmngr != null) {ntfmngr.cancelAll();}
0 0
- android的notification的写法
- Notification基本通知的两种写法
- Android-Notification的使用
- Android Notification的使用
- android Notification 的使用
- android Notification 的使用
- Android Notification 的使用
- Android-Notification的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification的使用
- android notification 的用法
- android notification的用法
- android Notification 的使用
- android Notification 的使用
- Matlab微分进化算法及优化函数测试
- developer.biao.daily.20140801
- Matlab遗传算法性能测试
- 13.9 Edit Distance
- 创业公司铁律——“一个中心,两个基本点,四项基本原则,三个代表”
- android的notification的写法
- 4 随机现实图片特效
- 添加删除软件不能正常使用
- java 源码与API
- java 容器
- USACO Cowcycles 解题报告
- C# sql Server 项目数据库连接方式探讨
- crmsql查询用户登录信息
- 今日作息及食谱(8.2)