본문 바로가기

6. With IT/6.1 Android

GCM 푸시서버연동 설정 - Server

지난 시간에 이어, 이번에는 Server 설정을 해보자!!


1. 서버 구현시, 추가로 필요한 라이브러리들


gcm-server.jar


json-simple-1.1.1.jar


2. 프로젝트 생성 후 위 라이브러리들을 추가



3. 소스코드 추가 및 수정


public class Main
{
	public static void main(String[] args)
	{
		// 프로젝트 서버 API key 입력
		Sender sender = new Sender("프로젝트 서버 API key 입력"); 
		// GCM으로부터 발급받은 단말기 RegID 입력. 
		String regId = " GCM으로부터 발급받은 단말기 RegID 입력.";
		Message message = new Message.Builder().addData("msg", "push notify")
				.build();
		List

list = new ArrayList(); list.add(regId); MulticastResult multiResult; try { multiResult = sender.send(message, list, 5); if (multiResult != null) { List resultList = multiResult.getResults(); for (Result result : resultList) { System.out.println(result.getMessageId()); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

4. 실행하면 Client(단말)쪽에 Notifacation으로 위에서 테스트한 내용이 나타날 것이다!!

    Received:Bundle[{msg=push notify, from... 어쩌구 저쩌구


'6. With IT > 6.1 Android' 카테고리의 다른 글

UI와 Handler  (0) 2015.07.27
FragmentPagerAdapter, FragmentStatePagerAdapter의 사용  (0) 2015.05.18
GCM 푸시서버연동 설정 - Client  (3) 2015.04.10
ScalableLayout  (0) 2015.03.06
EventBus기법  (0) 2015.03.06