关于《第一行代码》中安卓通知的修改
2016-04-12 11:43
288 查看
最近在学安卓,在看郭霖大神的第一行代码,其中通知章节中用到如下代码:
Notification notification = new Notification(R.drawable.strawberry,"this is ticker text",System.currentTimeMillis());
在android studio中显示该方法已被废弃,所以自己找到如下替换方案,方便新手学习:
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.this).setSmallIcon(R.drawable.strawberry) .setContentTitle("this is title") .setContentText("this is text"); mBuilder.setTicker("this is the trick"); //构建一个Intent Intent resultIntent = new Intent(this,NotificationActivity.class); //封装一个Intent PendingIntent resultPendingIntent = PendingIntent.getActivity( this, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT); // 设置通知主题的意图 mBuilder.setContentIntent(resultPendingIntent); manager.notify(1,mBuilder.build());
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法