Notification

 

public class MainActivity extends Activity implements OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = (Button) findViewById(R.id.test);
        button.setOnClickListener(this);

    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        
        NotificationManager nm = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder notification = new Notification.Builder(this)
                .setContentTitle("111").setContentText("222")
                .setSmallIcon(R.drawable.ic_launcher).setOngoing(true)
                .setAutoCancel(false).setDefaults(Notification.DEFAULT_LIGHTS)
                .setLights(0xff0000ff, 300, 100).setWhen(0);

        nm.notify(this.hashCode(), notification.build());
    }
}

 

posted @ 2015-04-01 18:47  牧 天  阅读(191)  评论(0)    收藏  举报