Android 通知Notification的两种实现方法
2016-04-26 23:05
495 查看
public class NotificationActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); } public void notifyNew(View view){ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification.Builder builder = new Builder(this); builder.setContentTitle("通知标题"); builder.setContentText("帖子内容"); builder.setSmallIcon(R.drawable.ic_launcher); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); Notification notification = builder.build(); nm.notify(0, notification); } @SuppressWarnings("deprecation") public void notifyOld(View view){ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, "通知来了", System.currentTimeMillis()); Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:123456")); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); notification.setLatestEventInfo(this, "标题", "内容", contentIntent); nm.notify(0, notification); } }
相关文章推荐
- Android.mk编译APK范例
- Android中如何查看内存
- <Android Framework 之路>多线程
- <Android Framework 之路>多线程
- Android Studio对比代码的方法
- 深入浅出 - Android系统移植与平台开发(八)- Android系统的本地服务
- Android带图片的Toast(自定义Toast)
- Android Studio快捷键
- android平台添加新语种
- android AsyncTask和Handler对比
- Android应用Loaders全面详解及源码浅析
- Android开发之50个常见实用技巧——添加悦目的动画效果
- Android Studio基础设置和常用操作
- android 主线程和子线程之间的消息传递
- 关于Android 添加系统级(java)服务和调用的编写实现说明
- android 主线程和子线程之间的消息传递
- 百度地图开发环境配置
- Android:AIDL使用详解
- 多款Android播放器源码集锦(附开发教程)
- 20145308刘昊阳 《Java程序设计》实验四 Android环境搭建 实验报告