package com.example.notificationtest;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
Button sendNotice = (Button) findViewById(R.id.send_notice);
sendNotice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent pendindIntent = PendingIntent.getActivity(
MainActivity.this, 0, new Intent(MainActivity.this,
Notification.class), PendingIntent.FLAG_CANCEL_CURRENT);
Notification notification = new Notification.Builder(
MainActivity.this).setSmallIcon(R.drawable.ic_launcher)
.setTicker("it's ticker text" )
.setContentTitle("content title")
.setContentText("content text")
.setContentIntent(pendindIntent).build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(1, notification);
}
});
}
}
为什么我的notification设置了setTicker("it's ticker text" )也不会在status bar出现??