Fire Base NO SQL ฟรี!
สวัสดีครับ วันนี้เราจะมาแนะนำวิธีการทำฐานข้อมูลโดยการบริการจาก Google นั้นคือ Firebase นั้นเอง ในอนาคตบริการอาจจะไม่ฟรีก็ได้นะครับ แต่ถึงยังไงก็อยากให้ Google เปิดเป็นบริการที่ฟรีต่อไปนะครับ เพื่อช่วยให้นักพัฒนาได้พัฒนาความสามารถของตนเองครับ เรามาเริ่มวิธีการทำกันเลยครับ
เรื่มต้นใช้งานโดยการไปที่ ลิงค์ https://console.firebase.google.com
1. เพิ่มโครงงาน (แล้วสร้างโครงงาน) เราสามารถเลือกผลิตภัณฑ์ที่เราจะสร้างได้ มีทั้ง IOS Android Web ในที่นี้เราก็เลือกทำแอนดรอย
2. firebase กรอก 3 ช่อง
- ชื่อแพ็กเกจ Android เปิดไฟล์ manifests/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.todo.geekcreator.walk">
.
.
.
</manifest>
เปิดไฟล์ values/google_maps_api.xml
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "CrXXte" at the end:
https://console.developers.google.com/flows/enablXXpi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=E2:7B:B6:98:EE:EE:B0:A4:AF:4D:F9:8B:10:BE:36:XX:XX:XX:XX:XX%3Bcom.todo.geekcrXXtor.walk
You can also add your credentials to an existing key, using these values:
Package name:
E2:7B:B6:98:EE:EE:B0:A4:AF:4D:F9:8B:10:BE:36:XX:XX:XX:XX:XX
SHA-1 certificate fingerprint:
E2:7B:B6:98:EE:EE:B0:A4:AF:4D:F9:8B:10:BE:36:XX:XX:XX:XX:XX
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyDiY-xLMjziFOnHmGWd4vz29dmnqp7fnl8</string>
</resources>
แล้วกดลงทะเบียนแอป
3. ดาวน์โหลดไฟล์กำหนดค่า
- ดาวน์โหลดไฟล์ google-services.json
- เปลี่ยนรูปแบบของโปรเจ็ค ในขั้นตอนนี้ทุกคนอาจจะงงก็ได้นะครับ เดี่ยวทำให้เป็นรูปภาพแล้วกันครับ แล้วเลือก project
- ไฟล์ google-services.json ย้ายไฟล์ google-services.json ไปเก็บไว้ใน app/google-services.json
- เปลี่ยนรูปแบบของโปรเจ็คกลับมาเป็นเหมือนเดิม เลือก Android
4. เปิดไฟล์ Gradle Script/build.gradle(Project: ...)
เพิ่ม classpath 'com.google.gms:google-services:3.1.0' แล้วกด Sycn Now
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
5.เปิดไฟล์ Gradle Script/build.gradle(Module: app)
เพิ่ม apply plugin: 'com.google.gms.google-services' ไว้ข้างล่างสุด แล้วกด Sycn Now
เพียงเท่าก็สามารถใช้งานFirebase ไดแล้วครับ *หากมีปัญหาตอน build ไฟล์ ก็ควรเพิ่ม packagingOptions ด้วยนะครับ
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.todo.geekcreator.walk"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services-maps:10.2.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
สำหรับการใช้งาน Firebase ก็ขอจบไว้เพียงเท่านี้ครับ หากมีข้อสงสัยหรือต้องการวิธีในการทำแอปพลิเคชันแบบต่างๆ ก็สามารถคอมเมนต์ไว้ได้ที่โพสต์ด้านล่างเลยครับ สำหรับวันนี้สวัสดีครับ




สอนวิธีดึงข้อมูลมาใช้หน่อยสิ
ตอบลบ