Android:可以在后台服务中使用Firebase远程配置吗?

时间:2017-05-31 09:37:28

标签: android firebase android-service firebase-remote-config

我想在后台服务(我用来显示通知)中使用Firebase远程配置。有可能这样做吗?

为了更准确,是否可以在后台服务中获取远程值?

// Code below in a background service ?
mFirebaseRemoteConfig.fetch(cacheExpiration).addOnCompleteListener(this, new OnCompleteListener<Void>() {

    @Override
    public void onComplete(@NonNull Task<Void> task) {
             // get remote values here            

    }
 }

谢谢!!!

2 个答案:

答案 0 :(得分:4)

回答我自己的问题!是的,有可能,只需删除“这个&#39;在addOnCompleteListener中。它给出了:

mFirebaseRemoteConfig.fetch(cacheExpiration).addOnCompleteListener(new OnCompleteListener<Void>() {

    @Override
    public void onComplete(@NonNull Task<Void> task) {
             // get remote values here            

    }
 }

似乎在后台服务中完美运作。

答案 1 :(得分:0)

您是否尝试过阅读手册? https://firebase.google.com/docs/remote-config/android

 @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Toast.makeText(MainActivity.this, "Fetch Succeeded",
                            Toast.LENGTH_SHORT).show();

                    // After config data is successfully fetched, it must be activated before newly fetched
                    // values are returned.
                    mFirebaseRemoteConfig.activateFetched();
                } else {
                    Toast.makeText(MainActivity.this, "Fetch Failed",
                            Toast.LENGTH_SHORT).show();
                }
                displayWelcomeMessage();
            }