package cn.edu.xjau.notificationtest;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;
import android.view.View;
import android.widget.Button;

public class MainActivity  extends AppCompatActivity {
    private int numMessage = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.send_notice);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.send_notice:
                        setSendNotificationBtn();
                        break;
                    default:
                        break;
                }
            }
        });
    }

    public void setSendNotificationBtn () {
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        

        //NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        Notification notification = new NotificationCompat.Builder(MainActivity.this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setWhen(System.currentTimeMillis())
                //根据给定的资源Id解析成位图
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                .setTicker("Look Look!!")
                .setContentTitle("My Notification")
                .setContentText("Hello Notification")
                .build();

        //builder..setSmallIcon(R.mipmap.ic_launcher)
        //builder.setContentIntent(pendingIntent);
        //Notification notification1 = builder.build();

        manager.notify(1, notification);
    }
}
