티스토리 뷰
1. 먼저 https://firebase.google.com/ 로 접속해서 우측 상단의 콘솔로 이동하기를 누릅니다.
2. 파이어 베이스 프로젝트 생성하기를 클릭하여 프로젝트를 생성합니다.
3. 파이어베이스를 사용하기 위해서는 사용할 앱을 등록해야 합니다.
화면 중앙에서 android 앱에 firebase 추가를 클릭합니다.
4. 파이어베이스를 사용하고자 하는 앱의 패키지 명을 입력하고 앱추가를 클릭합니다.
디버그 서명 인증서 SHA-1이나 앱 닉네임은 선택사항이므로 입력하지 않아도 좋습니다.
5. 앱추가를 누르고 나면 다음과 같은 화면과 함께 google-services.json 파일이 다운로드 됩니다.
계속을 눌러 넘어갑니다.
6. 안드로이드 앱을 개발할때 파이어베이스를 연동하려면 어떻게 해야할지에 대한 가이드가 나옵니다.
완료를 눌러 넘어갑니다.
7. 이제 안드로이드 프로젝트를 생성합니다.
이때 패키지 이름은 파이어베이스 프로젝트를 생성할때 입력했던 프로젝트 이름과 동일해야합니다.
6번에서 보았던 1번 프로젝트 수준 gadle 파일과 2번 앱 수준 gradle 파일에 각각 6번에서의 코드를 삽입합니다.
8. 파이어 베이스 프로젝트를 생성할때 다운로드 되었던 google-services.json 파일을 app 디렉토리에 복사합니다.
9. 파이어 베이스의 애널러틱스 서버로 로그를 보낼 것이기 때문에 AndroidManifest.xml 에 아래의 권한을 추가합니다.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.kim.test.MainActivity"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="User ID" android:textSize="20dp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/user_id" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20dp" android:text="User Name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/user_name" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send Event" android:id="@+id/btn_sendEvent" android:layout_gravity="center_horizontal" android:onClick="onClick" /> </LinearLayout> </RelativeLayout> | cs |
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | package com.example.kim.test; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; import android.widget.Toast; import com.google.firebase.analytics.FirebaseAnalytics; import static com.example.kim.test.R.id.user_pw; public class MainActivity extends AppCompatActivity { private FirebaseAnalytics mFirebaseAnalytics; EditText txt_user_id, txt_user_name; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); txt_user_id = (EditText) findViewById(R.id.user_id); txt_user_name = (EditText) findViewById(R.id.user_name); } public void onClick(View v){ switch(v.getId()) { case R.id.btn_sendEvent: String user_id, user_name; user_id = txt_user_id.getText().toString(); user_name = txt_user_name.getText().toString(); Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_ID, user_id); bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, user_name); mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); Toast.makeText(getApplicationContext(), "Sent event", Toast.LENGTH_LONG).show(); break; } } } | cs |
'파이어 베이스' 카테고리의 다른 글
파이어 베이스 데이터베이스 사용 (0) | 2016.11.24 |
---|
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 한글
- Google Map
- 웹
- django
- 추상 클래스
- 팩토리 패턴
- 구글 맵
- cmd
- flask
- 한글깨짐
- 안드로이드
- 구글맵
- Windows
- 에 잚
- 심플 팩토리 패턴
- Python
- 깨짐
- 팩토리 메소드 패턴
- 한글 깨짐
- 플라스크
- ㄹ
- git log
- Git
- Windwos
- 파이썬
- Apache
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함