프로그램/Android

안드로이드 Notification 이미지와 큰사이즈

잡식성초보 2017. 8. 28. 14:37

이번에는 안드로이드 Notification에 대한 설명입니다.

아직 제가 node를 공부한게 아니라서 서버를 직접 구현해 놓지 않은 관계로 로컬에서 


notification을 사용합니다.(차후 node.js 공부할 예정!)

처음에는 어떻게 큰 사이즈를 만들지?늘렸다 줄였다 하는 저것은 custom이나 다른 함수가 있


지 않을까?라고 생각했었는데 그게 아니었다. BigTextStyle Notification을 생성하여 기본으


로 만든 notification을 넣어주면 자동적으로 생성되는 것이었다


소스는 아래와 같습니다.



public class LocalNotificationActivity extends Activity {

    private Context mContext;
    private Button btn_send_noti;

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

        mContext = LocalNotificationActivity.this;
        btn_send_noti = (Button)findViewById(R.id.btn_send_noti);
        btn_send_noti.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                /**     기본 Notification     **/

                String title = "Local Noti";
                String content = "Local Notification Testing";
                String ticker = "One Line Local Notification Text";

                Intent notiIntent = new Intent(LocalNotificationActivity.this, LocalNotificationConfirm.class);     //클릭시 이동시킬 Activity
                notiIntent.putExtra("notiId", 8888);
                PendingIntent pendingIntent =
                        PendingIntent.getActivity(LocalNotificationActivity.this, 0, notiIntent, PendingIntent.FLAG_UPDATE_CURRENT);

//                NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
//                builder.setContentTitle(title);
//                builder.setContentText(content);
//                builder.setTicker(ticker);
//                builder.setSmallIcon(R.drawable.seul_2_image);
//                builder.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.seul_2_image));
//                builder.setContentIntent(pendingIntent);
//                builder.setAutoCancel(true);    //푸시 클릭시 자동 삭제허용
//                builder.setWhen(System.currentTimeMillis());
//                builder.setPriority(Notification.PRIORITY_HIGH);    //요거해줘야지 위에서 내려오는거 보임
//                builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); //Notification.DEFAULT_VIBRATE <- 얘가 진동
//
//                NotificationManager nm = (NotificationManager)getSystemService(mContext.NOTIFICATION_SERVICE);
//                nm.notify(1234, builder.build());


                /**     큰사이즈 Notification     **/
                NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext)
                        .setSmallIcon(R.drawable.seul_2_image)
                        .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.seul_2_image))
                        .setContentTitle(title)
                        .setContentText(content)
                        .setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                        .setContentIntent(pendingIntent);

                String bigContent = "리버풀은 28일 0시(한국 시간) 영국 리버풀 안필드에서 열린 2017-18 시즌 잉글랜드 프리미어리그(EPL) 3라운드 아스널과 경기에서 4-0으로 이겼다. 전방 스리톱이 한 골씩 기록했다.";

                NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(notificationBuilder);
                style.bigText(bigContent).setBigContentTitle("긴글 테스트입니다.");

                /**     글 대신 큰 이미지 넣을경우     **/
//                NotificationCompat.BigPictureStyle style1 = new NotificationCompat.BigPictureStyle(notificationBuilder);
//                style1.bigPicture(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.seul_2_image)).setBigContentTitle(title);

                NotificationManager nm1 = (NotificationManager)getSystemService(mContext.NOTIFICATION_SERVICE);
                nm1.notify(1234, notificationBuilder.build());
            }
        });
    }
}


반응형