4. 이클립스 + FCM
Eclipse/(Fail) FCM with Eclipse.No support By G이클립스에서 FCM 기반 앱 개발하기 위한 준비 사항.
1. 안드로이드 앱 프로젝트를 시작한다.
2. FCM 라이브러리를 이클립스에 설치한다.
http://storycode.tistory.com/13 참조
3. google-play-serivces_lib 프로젝트를 import 한다.
- SDK Manager 에서 최신 버전을 설치하면 google-play-serivces_lib 프로젝트가 존재하지 않는 것 같다.
- 그래서, 아래의 포스트에서 google-play-services_lib 프로젝트를 다운로드 받아서 import 한다.
* http://blog.naver.com/websearch/220830144941
- google-play-services_lib 프로젝트를 import 하는 이유는 firebase 에서 google-play-service 를 필요로 하고 해당 R 클래스도 필요로 하기 때문이다.
- import 한 google-play-services_lib 를 FCM 앱의 라이브러리로 포함시킨다.
4. FCM 을 위한 google-services.json 파일 다운로드 및 적용
{
private static String TAG = "MainActivity";
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
FirebaseMessaging clsMessaging = FirebaseMessaging.getInstance();
clsMessaging.subscribeToTopic("news");
String token = FirebaseInstanceId.getInstance().getToken();
Log.e( "token2", "token[" + token + "]" );
}
}
{
private static final String LOG_TAG = "FCMIDService";
@WorkerThread
public void onTokenRefresh()
{
super.onTokenRefresh( );
String strToken = FirebaseInstanceId.getInstance().getToken();
Log.d( LOG_TAG, "token[" + strToken + "]" );
}
}
8. FCM 메시지 이벤트 수신
- FCM 메시지 이벤트 수신을 위한 서비스를 개발한다. 클래스 이름은 AndroidManifest.xml 에 기술한 이름과 동일해야 한다.
public class FCMService extends com.google.firebase.messaging.FirebaseMessagingService
{
private static final String LOG_TAG = "FCMService";
@Override
@WorkerThread
public void onMessageReceived( RemoteMessage arg0 )
{
super.onMessageReceived( arg0 );
Map<String,String> clsData = arg0.getData( );
for( Map.Entry<String, String> it : clsData.entrySet( ) )
{
Log.d( LOG_TAG, "key(" + it.getKey( ) + ") value(" + it.getValue( ) + ")" );
}
Notification clsNotification = arg0.getNotification( );
if( clsNotification != null )
{
Log.d( LOG_TAG, "notification body(" + clsNotification.getBody( ) + ")" );
}
}
}
[출처] [안드로이드] 이클립스에서 FCM 기반 앱 개발 방법|작성자 까미유
[추가정보1]
3. google-play-serivces_lib 프로젝트를 import 한다. 수행시
google-play-services_lib 를 단순히 Java Build Path 의 Libraries 에 추가하면
clsMessaging.subscribeToTopic("news");
String token = FirebaseInstanceId.getInstance().getToken();
'Eclipse > (Fail) FCM with Eclipse.No support By G' 카테고리의 다른 글
6. 추가 설정 (0) | 2018.05.02 |
---|---|
5. 이클립스에 FCM Jar 설치하는 방법 (0) | 2018.04.30 |
3. App 에 등록 (0) | 2018.04.26 |
2. FireBase 에서 프로젝트 만들기 (0) | 2018.04.26 |
1. 새 프로젝트 만들기 (0) | 2018.04.26 |