Android开发之通知栏

手机中常常用没有处理的通知消息等,这些通知会被放到通知栏,用户拉下屏幕遮罩层的时候会在层上显示,类似这样的功能实现方法,可以用android提供的Notification来实现。
addNotificaction() {  
        NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        // 创建一个Notification  
        Notification notification = new Notification();  
        // 设置显示在手机最上边的状态栏的图标  
        notification.icon = R.drawable.icon;
        // 提示信息
        notification.tickerText = "状态栏通知";
        // 添加声音
        notification.defaults=Notification.DEFAULT_SOUND;
        // audioStreamType的值必须AudioManager中的值,代表着响铃的模式  
        notification.audioStreamType= android.media.AudioManager.ADJUST_LOWER;
        //下边的两个方式可以添加音乐  
        //notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");
        //notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        // 点击状态栏的图标出现的提示信息设置  
        notification.setLatestEventInfo(this, "提示:", "测试Notification", pendingIntent);
        manager.notify(1, notification);
    }

猜你喜欢

转载自nujack.iteye.com/blog/1908355