Android学习日记(yzy):Notification的简单运用
来源:互联网 发布:淘宝网紫斑牡丹苗 编辑:程序博客网 时间:2024/06/03 19:05
最近,老大要我修改一个蓝牙通知apk的软件异常,即在android6.0的情况下apk会报出sorry!apk exception,will
exit 的异常,后来发现,这个版本中Notiication移除了最初的方法Notification.setLatestEventInfo(),我们在
SDK23版本之后只能使用Notification.Builder来获取实例。再就是运行时的权限问题,蓝牙的扫描需要在Activity动
态的添加LOCATION的权限。具体的API功能差异可查看http://blog.csdn.net/t000818/article/details/52218574。
和http://blog.csdn.net/tangxl2008008/article/details/51334604。
因此,简单的写一下,在使用build的情况下的消息通知推送功能代码:
消息功能最重要的两个类为:类NotificationManager 和 类Notification ,Notification 负责将要执行的
功能和参数,再通过NotificationManager 推送出来,类PendingIntent则实现再点击通知框时的跳转功能。代码如下:
public class MainActivity extends Activity { final static private String TAG = "MainActivity"; private NotificationManager notificationManager = null; private PendingIntent contentIntent = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); notificationManager = (NotificationManager)this.getSystemService(NOTIFICATION_SERVICE); } public void onClick(View view){ Log.e(TAG,"click successfully "); setNotification(); } private void setNotification(){ Intent intent = new Intent(com.yzy.btnoticationdemo.MainActivity.this,com.yzy.btnoticationdemo.SecondActivity.class); contentIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0); Bitmap mBitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.app_info); Notification notification = new Notification.Builder(this) .setContentTitle("New mail from Notification") .setContentText("this is the detail content from Notification") .setSmallIcon(R.mipmap.app_info) .setLargeIcon(mBitmap) .setContentIntent(contentIntent) .build(); notificationManager.notify(0, notification); }}
0 0
- Android学习日记(yzy):Notification的简单运用
- Android学习日记(yzy):Fragment与VierPager简单实现
- Android学习日记(yzy):intent传递的多种数据类型
- Android学习日记(yzy):Service的两种启动
- Android学习日记(yzy):显示application并调用
- Android学习日记(yzy): Accessibility辅助功能
- Android学习日记(yzy):集成布局和滑动效果的实现
- Android学习日记(yzy):Broadcast Receiver的注册和发送
- Android学习日记(yzy):opengl 绘制2d图形 基本框架
- Android学习日记(yzy):通过Timer类和Handler机制实现gif图片
- Android学习日记(1):Notification
- android学习日记:AsyncTask的运用
- Android Notification通知的运用
- Android 中Notification的运用
- C语言学习日记(yzy):socket(TCP)网络连接
- android学习日记:fragment运用
- Android学习之Notification的简单使用
- 菜鸟日记(yzy) 微信公众号网页的开发-websocket
- <三>修改树莓派软件源,加快apt-get速度
- hadoop学习之HDFS(2.6):wordcount例子代码详细解读
- IE11浏览器中的My97日历控件刷新后无法打开问题解决办法
- Microsoft Access数据库操作类(C#)
- MyEclipse安装FindBugs 插件
- Android学习日记(yzy):Notification的简单运用
- javascript书籍推荐
- mysql字段修改
- 安卓中内存问题
- 安卓热修复之AndFIX
- 发布要素地图服务(Feature Layer)
- 【log】log4j 1.2
- LikesLayout 向上升的效果
- 百度地图v3.0.0的sdk跟一些第三方库(MBProgressHUD、Reachability)冲突 解决方案