// MainActivity.java
package com.example.administrator.notification;
import android.app.Notification;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationManager manager = (NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
Notification.Builder b = new Notification.Builder(this);
b.setTicker("支付宝到账一百万元");
b.setSmallIcon(R.mipmap.ic_launcher);
b.setContentText("通知内容");
b.setContentTitle("通知标题");
manager.notify(1,b.getNotification());
NotificationCompat.Builder b1 = new NotificationCompat.Builder(this);
b1.setContentTitle("通知标题");
b1.setContentText("通知内容");
b1.setSmallIcon(R.mipmap.ic_launcher);
b1.setTicker("通知的提示消息");
manager.notify(2,b1.build());
}
}
网友评论