android通知(Notification)的使用
来源:互联网 发布:stc8f单片机 编辑:程序博客网 时间:2024/06/09 20:03
需要注意的几点:
1.通知的类型,一般普通的消息事件和正在进行的事件
2.通知的布局是可以自定义的
3.通知在android4.1以后,还支持一种detail的通知,(就是可扩展的)
4.通知的行为,常规的和按照堆栈顺序的
activity的配置:
<activity android:name="com.example.testnotification.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- 确保这次活动是独立的,不影响应用默认的使用范围 --> <activity android:name="com.example.testnotification.ResultActivity" android:excludeFromRecents="true" android:label="@string/title_activity_result" android:launchMode="singleTask" android:taskAffinity="" > </activity> <!-- 具有保持应用程序堆栈顺序的,通知 --> <activity android:name="com.example.testnotification.Result2Activity" android:label="@string/title_activity_result2" android:parentActivityName="com.example.testnotification.MainActivity" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.testnotification.MainActivity" /> </activity>
示例代码:
/** * 测试发送一个普通行为的通知 通知在点击后,进入resultactivity,点击返回将直接结束 * * @param v */public void onBtn1(View v) {// 构造通知,目前已经将直接使用构造方法的方式淘汰了NotificationCompat.Builder builder = new NotificationCompat.Builder(this);builder.setContentTitle("jiba");builder.setContentTitle("狗日傻逼");builder.setAutoCancel(true);builder.setSmallIcon(R.drawable.ic_launcher);// 通知的活动Intent notifyIntent = new Intent(this, ResultActivity.class);// Sets the Activity to start in a new, empty tasknotifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK);// Creates the PendingIntentPendingIntent contentIntent = PendingIntent.getActivity(this, 0,notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);// Puts the PendingIntent into the notification builderbuilder.setContentIntent(contentIntent);// 最后完成通知发送NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);mNotificationManager.notify(1, builder.build());}/** * 发送保持堆栈的通知 * @param v */public void onBtn2(View v) {Intent resultIntent = new Intent(this, Result2Activity.class);TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);// Adds the back stackstackBuilder.addParentStack(Result2Activity.class);// Adds the Intent to the top of the stackstackBuilder.addNextIntent(resultIntent);// Gets a PendingIntent containing the entire back stackPendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);NotificationCompat.Builder builder = new NotificationCompat.Builder(this);builder.setContentTitle("jiba2");builder.setContentTitle("狗日傻逼2");builder.setSmallIcon(R.drawable.ic_launcher);builder.setAutoCancel(true);builder.setTicker("oh,jibalema");builder.setContentIntent(resultPendingIntent);NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);mNotificationManager.notify(10, builder.build());}
- 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详解
- Android的通知(Notification)使用详解
- Android中通知的使用-----Notification详解
- scrapy使用方法概要
- 代号诺曼底,诺基亚Lumia风格新机曝光
- ActiveMQ使用线程池实现消息的生产与消费
- 网页中输出漂亮格式的Php数组神器
- POJ 3468
- android通知(Notification)的使用
- 百度地图API详解之地图坐标系统
- SQL Server 2000导入SQL Server 2005生成脚本的问题
- Spring Data JPA 简单介绍
- 开源电子商务平台:OfBiz
- CCNode
- 虚拟主机系统
- linux mount用法,和如何挂载光驱、软驱、U盘
- MySQL数据库中的Date,DateTime和TimeStamp类型