Android Programlama – Firebase Remote Config
Merhabalar,
Bugün ki dersimizde Firebase Remote Config ‘i inceleyeceğiz. Firebase Remote Config, uygulama için yeni bir güncellemeye gerek duymadan uygulamanın davranışını değiştiren yapıdır.
Peki nasıl bir davranış ? Örneğin uygulamanızda arka plan rengini bir süre sonra değiştirmek istiyorsunuz, ya da günün anlam ve önemine göre bir ekran yapmak istiyorsunuz. Her seferinde güncelleme atmaya gerek olmadığını, aslında değişecek yapının text ve image olduğunu biliyorsunuz. İşte bunu console üzerinde gerekli parametreler ile rahatlıkla güncelleyebiliyorsunuz.
Nasıl Çalışır?
Remote Config , içerdiği kütüphane sayesinde parametrelerin değerlerini getirme ve önbelleğe alma gibi görevleri gerçekleştirip, değerlerin etkinleştirilme sürecini denetler.
Uygulamanın hangi yönlerinin Remote Config kullanılarak değiştirilebileceği tanımlanır , ardından uygulamanızda kullanılabilecek parametrelere dönüştürülür.Uygulamaya da az sayıda kod satırıyla Remote Config parametreleri için uygulama içi default değerler ayarlanır.
Uygulamanızda ki metinler,resimler,renkler vb. değişkenleri bu sayede kolay bir şekilde değiştirebilirsiniz.Fakat kullanıcı yetkilendirmesine dayalı gizli verilerin bu parametrelere eklenmemesinde fayda var.
Ayrıca Firebase Analytics ile entegreli olan Remote Config , belirli kitle ve dil vb. durumlara göre de yapılandırma imkanı sağlamakta.
dependencies { implementation 'com.google.firebase:firebase-config:11.8.0' } apply plugin: 'com.google.gms.google-services'
package com.umitkose.firebaseremoteconfig; import android.graphics.Color; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.remoteconfig.FirebaseRemoteConfig; import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; public class MainActivity extends AppCompatActivity { private static final String TAG = MainActivity.class.getSimpleName(); //parametre anahtarları private static final String TEXT = "text"; private static final String COLOR = "background"; FirebaseRemoteConfig mRemoteConfig; View container; TextView text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); container = (View) findViewById(R.id.container); text = (TextView) findViewById(R.id.textView); //FirebaseRemoteConfig sınıfı nesnelerini kullanmamızı sağlayan metod mRemoteConfig = FirebaseRemoteConfig.getInstance(); //Bir Remote Config Settings olusturup developer modunu aktif hale getiriyoruz. FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnabled(BuildConfig.DEBUG) .build(); mRemoteConfig.setConfigSettings(configSettings); //Hazırlanan key-value ları set ediyoruz mRemoteConfig.setDefaults(R.xml.firebaseconfig); fetch(); } private void fetch() { long cacheExpiration = 0; if (mRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) { cacheExpiration = 0; } mRemoteConfig.fetch(cacheExpiration) .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "Fetch succeeded."); mRemoteConfig.activateFetched(); String colorName = mRemoteConfig.getString(COLOR); Log.d(TAG, "colorName: " + colorName); container.setBackgroundColor(Color.parseColor(colorName)); String textLabel = mRemoteConfig.getString(TEXT); Log.d(TAG, "textLabel: " + textLabel); text.setText(textLabel); } else { Toast.makeText(MainActivity.this, "Fetch Failed", Toast.LENGTH_SHORT).show(); } } }); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:app="//schemas.android.com/apk/res-auto" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tools="//schemas.android.com/tools" tools:context="com.umitkose.firebaseremoteconfig.MainActivity" xmlns:android="//schemas.android.com/apk/res/android"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:text="" android:textAllCaps="true" android:textSize="25dp" app:layout_constraintLeft_toLeftOf="@+id/fire" app:layout_constraintRight_toRightOf="@+id/fire" app:layout_constraintTop_toBottomOf="@+id/fire" tools:layout_constraintLeft_creator="1" tools:layout_constraintRight_creator="1" /> </android.support.constraint.ConstraintLayout>
Merhaba Ümit KÖSE bey ,
PDF Viewer kütüpaneyi import etmek için nereden indirebiliriz ?
Teşekkürler
Saygılarımla