说明:
根据项目选择的基础sdk,选择不同的创建Notification的方法
1 在android sdk 3.0 之前直接通过 new Notification的方法直接创建通知对象

2 在android sdk 3.0 是通过Notification.Builer的方法间接配置Notification的属性和创建Notification的功能

3 在android sdk4.0以上 是通过android-support-v4.jar 包中的NotificationCompat.Builder类,进行配置创建Notification对象


下面是一个实例,用NotificationCompat.Builder的方式创建Notification

NotificationCompat.Builder mBuilder =                new NotificationCompat.Builder(this)                .setSmallIcon(R.drawable.ic_launcher)                .setContentTitle("My notification")                .setContentText("Hello World!");                //Notification.Builder builder=new Notification.Builder(this);                 mBuilder.setAutoCancel(true);        mBuilder.setLights(Color.BLUE, 500, 500);        long[] pattern = {500,500,500,500,500,500};        mBuilder.setVibrate(pattern);                Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.messagevoice);        mBuilder.setSound(sound);        //mBuilder.setSound(sound);        // Creates an explicit intent for an Activity in your app        Intent resultIntent = new Intent(this, MessageShowActivity.class);        // The stack builder object will contain an artificial back stack for the        // started Activity.        // This ensures that navigating backward from the Activity leads out of        // your application to the Home screen.        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);        // Adds the back stack for the Intent (but not the Intent itself)        //stackBuilder.addParentStack(MessageShowActivity.class);        // Adds the Intent that starts the Activity to the top of the stack        stackBuilder.addNextIntent(resultIntent);        PendingIntent resultPendingIntent =                PendingIntent.getActivity(this, 0, new Intent(this,MessageShowActivity.class), 0);                mBuilder.setContentIntent(resultPendingIntent);        NotificationManager mNotificationManager =            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);        // mId allows you to update the notification later on.        mNotificationManager.notify(12, mBuilder.build());      

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. 类和 Json对象
  3. Python list sort方法的具体使用
  4. python list.sort()根据多个关键字排序的方法实现
  5. Android(安卓)AsyncTask
  6. Android(安卓)Drawable Resource学习(一)、Drawable Resource简介
  7. Android周学习Step By Step(6)--Android的数据库SQLite
  8. Android(安卓)WebView 开发详解(一)
  9. android sdk 的下载方法,其他的方法都是非常慢的

随机推荐

  1. 肝了一周总结的SpringBoot实战教程,太实用
  2. DockerHub访问慢怎么破?自建个企业级镜像
  3. 干掉Navicat!MySQL官方客户端到底行不行?
  4. PMP考试个人感想
  5. Elasticsearch官方已支持SQL查询,用起来贼
  6. 解放双手!MyBatis官方代码生成工具给力!
  7. 还在使用第三方Docker插件?SpringBoot官方
  8. 当Swagger遇上YApi,瞬间高大上了!
  9. Lombok有啥牛皮的?SpringBoot和IDEA官方都
  10. 干掉mapper.xml!MyBatis新特性动态SQL真香