Android通知代码
2016-05-13 14:45
381 查看
public void notice() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); Context context = getApplicationContext(); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0); Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Notification notification = new NotificationCompat// 注意:4.4.2版本使用的方法 .Builder(context) //上下文 .setAutoCancel(true) //自动取消 .setContentTitle("title") //标题 .setContentText("describe") //描述 .setContentIntent(contentIntent) //通知动作 .setSmallIcon(R.drawable.ic_launcher) //图标 .setWhen(System.currentTimeMillis()) //时间 .setSound(alert) //声音 .build(); //建立通知 mNotificationManager.notify(1, notification); }
相关文章推荐
- Android Studio使用gradle打包指定包名和类的jar
- Android ListView与EditText共存错位
- Android之dialog
- android studio导入so,bat文件
- Android字段验证的实例代码
- Android Dev Intro - Android Activity Lifecycle
- Android Viewpager拦截 左右滑动
- Android开发随手记录-AS导出jar包
- android的m、mm、mmm编译命令的使用
- Android系统中蓝牙设备间连接和通信
- android toast几种使用方法
- This version of the rendering library is more recent than your version of Android Studio. Please upd
- android 系统提示对话框(AlertDialog)的使用
- 7种形式的Android Dialog使用举例
- Android Studio编译报错:sdk:minSdkVersion 1 cannot be smaller than version 7 declared in library
- android进阶之路:大神问答
- Android打造带透明圆弧的ImageView
- Android TouchEvent事件传递机制
- Android 国际化语言
- Android 异常日志捕捉Crash