com.google.firebase.remoteconfig.FirebaseRemoteConfig Java Examples

The following examples show how to use com.google.firebase.remoteconfig.FirebaseRemoteConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScheduleFragment.java    From KUAS-AP-Material with MIT License 7 votes vote down vote up
private void getScheduleData() {
	mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
	FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
			.setDeveloperModeEnabled(BuildConfig.DEBUG).build();
	mFirebaseRemoteConfig.setConfigSettings(configSettings);

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

		@Override
		public void onComplete(@NonNull Task<Void> task) {
			if (task.isSuccessful() && !activity.isFinishing()) {
				mFirebaseRemoteConfig.activateFetched();
				try {
					mScheduleData = mFirebaseRemoteConfig.getString("schedule_data");
					setUpViews();
				} catch (Exception e) {
					// ignore
				}
			}
		}
	});
}
 
Example #2
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void executeAdsPolicy() {
    // [START pred_ads_policy]
    FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
    String adPolicy = config.getString("ads_policy");
    boolean will_not_spend = config.getBoolean("will_not_spend");
    AdView mAdView = findViewById(R.id.adView);

    if (adPolicy.equals("ads_always") ||
            (adPolicy.equals("ads_nonspenders") && will_not_spend)) {
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        mAdView.setVisibility(View.VISIBLE);
    } else {
        mAdView.setVisibility(View.GONE);
    }

    FirebaseAnalytics.getInstance(this).logEvent("ads_policy_set", new Bundle());
    // [END pred_ads_policy]
}
 
Example #3
Source File: CourseOutlineFragment.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
private void trackAATestCourseOutline() {
    if (!isVideoMode &&
            environment.getConfig().getFirebaseConfig().isEnabled()) {
        final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        firebaseRemoteConfig.fetchAndActivate().addOnCompleteListener(task -> {
            final String group = firebaseRemoteConfig.getString(Analytics.Keys.AA_EXPERIMENT);
            if (!TextUtils.isEmpty(group)) {
                final Map<String, String> values = new HashMap<>();
                values.put(Analytics.Keys.EXPERIMENT, Analytics.Keys.AA_EXPERIMENT);
                values.put(Analytics.Keys.GROUP, group);
                values.put(Analytics.Keys.USER_ID, environment.getLoginPrefs().getCurrentUserProfile().id.toString());
                values.put(Analytics.Keys.COURSE_ID, courseData.getCourse().getId());
                environment.getAnalyticsRegistry().trackExperimentParams(Analytics.Events.MOBILE_EXPERIMENT_EVALUATED, values);
            }
        });
    }
}
 
Example #4
Source File: HeartbeatFixerForGcmApp.java    From HeartbeatFixerForGCM with Apache License 2.0 6 votes vote down vote up
private void initFirebaseRemoteConfig() {
    final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
    config.setConfigSettings(new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build());

    Map<String, Object> defaults = new ArrayMap<>(1);
    defaults.put("ad", "{\"title\":\"Insgot - Repost for Instagram\",\"message\":\"Save, repost and share public "
            + "Instagram Photos & Videos in just one click!!!\","
            + "\"largeIconUrl\":\"https://scontent-iad3-1.cdninstagram"
            + ".com/vp/3d38d0a116646360fe0ea55b3653e594/5B9E635B/t51.2885-19/s150x150"
            + "/14719833_310540259320655_1605122788543168512_a.jpg\","
            + "\"bigPictureUrl\":\"https://scontent-iad3-1.cdninstagram"
            + ".com/vp/5209be0209350d926e79098b259158ff/5B887074/t51.2885-15/e35"
            + "/31928266_361115554410794_7648764144841129984_n.jpg\",\"version\":1,"
            + "\"landingPageUrl\":\"market://details?id=com.insgot.ins\"}");

    config.setDefaults(defaults);
}
 
Example #5
Source File: FirebaseUtil.java    From siberi-android with MIT License 6 votes vote down vote up
/**
 *
 * @param remoteConfig
 * @param testList
 * @return JSONArray of experiment data
 */
public static JSONArray convertFirebaseDataToJsonArray(FirebaseRemoteConfig remoteConfig, List<String> testList){
    JSONArray array = new JSONArray();
    Iterator iterator = testList.iterator();
    while (iterator.hasNext()) {
        JSONObject object = new JSONObject();
        String testName = (String) iterator.next();
        try {
            object.put(NAME, testName);
            String testValue = remoteConfig.getString(testName);
            if (TextUtils.isEmpty(testValue)) {
                object.put(VARIANT, -1);
            } else if (TextUtils.isDigitsOnly(testValue)) {
                object.put(VARIANT, testValue);
            } else {
                JSONObject meta = new JSONObject();
                object.put(VARIANT, -1);
                meta.put(VAL, testValue);
                object.put(METADATA, meta.toString());
            }
        } catch (JSONException e) {
        }
        array.put(object);
    }
    return array;
}
 
Example #6
Source File: AbstractDownloadHelper.java    From TvAppRepo with Apache License 2.0 6 votes vote down vote up
public AbstractDownloadHelper initialize(Activity activity) {
        mActivity = activity;
        mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        mFirebaseRemoteConfig.fetch().addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                mFirebaseRemoteConfig.activateFetched();
                AD_RATE = mFirebaseRemoteConfig.getLong("ad_rate");
            }
        });
/*        ColorTvSdk.init(activity, getAppId());
        ColorTvSdk.setRecordAudioEnabled(false);
        ColorTvSdk.onCreate();
        ColorTvSdk.registerAdListener(mListener);*/
        return this;
    }
 
Example #7
Source File: ClusterMapInfoFragment.java    From intra42 with Apache License 2.0 6 votes vote down vote up
private void updateButton() {

        if (!isAdded())
            return;

        buttonUpdate.setEnabled(true);
        buttonUpdate.setText(R.string.cluster_map_info_button_update);

        final FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        boolean warning_42tools_enable = mFirebaseRemoteConfig.getBoolean(getString(R.string.firebase_remote_config_warning_42tools_enable));
        if (activity.haveErrorOnLayer.contains(activity.layerSettingsInProgress.layer) && !warning_42tools_enable) {
            buttonUpdate.setEnabled(true);
            buttonUpdate.setText(R.string.retry);
        } else if (activity.layerSettings.equals(activity.layerSettingsInProgress)) {
            buttonUpdate.setEnabled(false);
            buttonUpdate.setText(R.string.cluster_map_info_button_update_disabled);
        }
    }
 
Example #8
Source File: OptimizePromotionsActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
private void initConfig() {
    // [START pred_optimize_promotions_init]
    mConfig = FirebaseRemoteConfig.getInstance();

    Map<String, Object> remoteConfigDefaults = new HashMap<>();
    remoteConfigDefaults.put("promoted_bundle", "basic");
    mConfig.setDefaultsAsync(remoteConfigDefaults)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        // Default value successfully set
                    } else {
                        // Failed to set default value
                    }
                }
            });
    // [END pred_optimize_promotions_init]
}
 
Example #9
Source File: ConditionalAdsActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void initRemoteConfig() {
    // [START pred_conditional_ads_init]
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

    Map<String, Object> remoteConfigDefaults = new HashMap<>();
    remoteConfigDefaults.put("ads_enabled", true);
    mFirebaseRemoteConfig.setDefaultsAsync(remoteConfigDefaults)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        // Default value successfully set
                    } else {
                        // Failed to set default value
                    }
                }
            });
    // [END pred_conditional_ads_init]
}
 
Example #10
Source File: MainActivity.java    From aircon with MIT License 6 votes vote down vote up
private void loadFireBaseConfig() {
	FirebaseRemoteConfig.getInstance()
	                    .fetch(0)
	                    .addOnSuccessListener(new OnSuccessListener<Void>() {
		                    @Override
		                    public void onSuccess(final Void aVoid) {
			                    FirebaseRemoteConfig.getInstance()
			                                        .activate();
			                    Log.i(App.TAG, "Firebase config loaded");
			                    onFireBaseConfigLoaded();
		                    }
	                    })
	                    .addOnFailureListener(new OnFailureListener() {
		                    @Override
		                    public void onFailure(@NonNull final Exception e) {
			                    Log.e(App.TAG, "Failed to load firebase config: " + e);
			                    onFireBaseConfigLoaded();
		                    }
	                    });
}
 
Example #11
Source File: SplashScreenActivity.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void initializeFirebase() {
    if (FirebaseApp.getApps(this).isEmpty()) {
        FirebaseApp.initializeApp(this, FirebaseOptions.fromResource(this));
    }
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    // [END get_remote_config_instance]

    // Create a Remote Config Setting to enable developer mode, which you can use to increase
    // the number of fetches available per hour during development. See Best Practices in the
    // README for more information.
    // [START enable_dev_mode]
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);
    // [END enable_dev_mode]

    // Set default Remote Config parameter values. An app uses the in-app default values, and
    // when you need to adjust those defaults, you set an updated value for only the values you
    // want to change in the Firebase console. See Best Practices in the README for more
    // information.
    // [START set_default_values]
    mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
    // [END set_default_values]
}
 
Example #12
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
public void executeGiftPolicy() {
    FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
    String giftPolicy = config.getString("gift_policy");
    boolean willChurn = config.getBoolean("will_churn");

    if (giftPolicy.equals("gift_achievement")) {
        grantGiftOnLevel2();
    } else if (giftPolicy.equals("gift_likelychurn") && willChurn) {
        grantGiftNow();
    }

    FirebaseAnalytics.getInstance(this).logEvent("gift_policy_set", new Bundle());
}
 
Example #13
Source File: FirebaseRemoteConfigValueImpl.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public long asLong() {
  if (source == FirebaseRemoteConfig.VALUE_SOURCE_STATIC) {
    return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_LONG;
  }

  String valueAsString = asTrimmedString();
  try {
    return Long.valueOf(valueAsString);
  } catch (NumberFormatException e) {
    throw new IllegalArgumentException(
        String.format(ILLEGAL_ARGUMENT_STRING_FORMAT, valueAsString, "long"), e);
  }
}
 
Example #14
Source File: MainActivity.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBinding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(mBinding.getRoot());

    mWelcomeTextView = mBinding.welcomeTextView;
    mBinding.fetchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fetchWelcome();
        }
    });

    // Get Remote Config instance.
    // [START get_remote_config_instance]
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    // [END get_remote_config_instance]

    // Create a Remote Config Setting to enable developer mode, which you can use to increase
    // the number of fetches available per hour during development. Also use Remote Config
    // Setting to set the minimum fetch interval.
    // [START enable_dev_mode]
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setMinimumFetchIntervalInSeconds(3600)
            .build();
    mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
    // [END enable_dev_mode]

    // Set default Remote Config parameter values. An app uses the in-app default values, and
    // when you need to adjust those defaults, you set an updated value for only the values you
    // want to change in the Firebase console. See Best Practices in the README for more
    // information.
    // [START set_default_values]
    mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
    // [END set_default_values]

    fetchWelcome();
}
 
Example #15
Source File: RxFirebaseConfig.java    From RxFirebase with Apache License 2.0 5 votes vote down vote up
@NonNull
public static Observable<Void> fetch(@NonNull final FirebaseRemoteConfig config) {
    return Observable.unsafeCreate(new Observable.OnSubscribe<Void>() {
        @Override
        public void call(final Subscriber<? super Void> subscriber) {
            RxTask.assignOnTask(subscriber, config.fetch());
        }
    });
}
 
Example #16
Source File: RxFirebaseConfig.java    From RxFirebase with Apache License 2.0 5 votes vote down vote up
@NonNull
public static Observable<Void> fetch(@NonNull final FirebaseRemoteConfig config, final long cacheExpirationSeconds) {
    return Observable.unsafeCreate(new Observable.OnSubscribe<Void>() {
        @Override
        public void call(final Subscriber<? super Void> subscriber) {
            RxTask.assignOnTask(subscriber, config.fetch(cacheExpirationSeconds));
        }
    });
}
 
Example #17
Source File: ZephyrConfigProvider.java    From zephyr with MIT License 5 votes vote down vote up
private void initFirebaseRemoteConfig() {
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);
    mFirebaseRemoteConfig.setDefaults(R.xml.config_defaults);
    mFirebaseRemoteConfig.fetch(Constants.FIREBASE_REMOTE_CONFIG_CACHE_EXPIRY_IN_SECONDS).addOnCompleteListener(ZephyrExecutors.getNetworkExecutor(), task -> {
        if (task.isSuccessful()) {
            mFirebaseRemoteConfig.activateFetched();
        }
    });
}
 
Example #18
Source File: CrossPromoActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private void initRemoteConfig() {
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);
    mFirebaseRemoteConfig.setDefaults(R.xml.defaults);
}
 
Example #19
Source File: RemoteConfigTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void prepareRemoteConfig() throws Exception {
  FirebaseRemoteConfig frc = FirebaseRemoteConfig.getInstance();

  waitForSuccess(frc.fetch());
  waitForSuccess(frc.activate());
}
 
Example #20
Source File: SplashScreenActivity.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
private void displayWelcomeMessage() {
    latestVersion = FirebaseRemoteConfig.getInstance().getString(
            "android_latest_version_name");
    Log.d(TAG, "onCreate: " + latestVersion);
    try {
        PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
        currentVersion = pInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    flow();
}
 
Example #21
Source File: NewOrderFragment.java    From Pharmacy-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

/*    mScanButton.setCompoundDrawablesWithIntrinsicBounds(
            VectorDrawableCompat.create(getResources(),R.drawable.ic_camera,null),
            null,null,null
    );*/

    params = new Bundle();
    mAnalytics = FirebaseAnalytics.getInstance(getContext());

    mRef = FirebaseDatabase.getInstance();

    mRemoteConfig = FirebaseRemoteConfig.getInstance();

    mRemoteConfig.setDefaults(R.xml.remote_config_defaults);

   mFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();

    // Check if user logged in else go back to login activity
    if (FirebaseAuth.getInstance().getCurrentUser() == null) {
        startActivity(LoginActivity.getInstance(getActivity()));
        getActivity().finish();
        return;
    }

}
 
Example #22
Source File: AboutPage.java    From Pharmacy-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mRemoteConfig = FirebaseRemoteConfig.getInstance();
        mRemoteConfig.setDefaults(R.xml.remote_config_defaults);

        mAnalytics = FirebaseAnalytics.getInstance(this);

        mRemoteConfig.fetch(2000)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        mRemoteConfig.activateFetched();
                    }
                });

//        setContentView(R.layout.activity_about_page);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        View aboutPage = new mehdi.sakout.aboutpage.AboutPage(this)
                .isRTL(false)
                .setImage(R.drawable.app_about_logo)
                .setDescription(getString(R.string.pharmacy_address))
                .addGroup("Connect with us")
//                .addEmail(getString(R.string.pharmacy_email_address))
                .addItem(pharmacyContactElement())
                .addGroup("Developed By")
                .addItem(authorElement())
                .addItem(appIconCreditElement())
                .addItem(iconCreditElement())
                .create();

        setContentView(aboutPage);
    }
 
Example #23
Source File: RxFirebaseRemoteConfig.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param config
 * @return
 */
@CheckReturnValue
@NonNull
public static Completable fetches(@NonNull final FirebaseRemoteConfig config) {
    return RxTask.completes(config.fetch()).doOnComplete(new Action() {
        @Override
        public void run() throws Exception {
            config.activateFetched();
        }
    });
}
 
Example #24
Source File: RxFirebaseRemoteConfig.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
@CheckReturnValue
@NonNull
public static Completable fetches(@NonNull final FirebaseRemoteConfig config,
                                  final long expiration) {
    return RxTask.completes(config.fetch(expiration)).doOnComplete(new Action() {
        @Override
        public void run() throws Exception {
            config.activateFetched();
        }
    });
}
 
Example #25
Source File: AdvertisementManager.java    From HeartbeatFixerForGCM with Apache License 2.0 5 votes vote down vote up
private AdvertisementManager(@NonNull Context context) {
    mContext = context.getApplicationContext();
    mPreferences = mContext.getSharedPreferences("ad", Context.MODE_PRIVATE);

    mLocalAdVersion = mPreferences.getInt("version", 0);

    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    mGson = new Gson();
}
 
Example #26
Source File: App.java    From aircon with MIT License 5 votes vote down vote up
private void initAirConSdk() {
	final AirCon airCon = AirCon.get();
	final FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
	firebaseRemoteConfig.setConfigSettings(new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG)
	                                                                                 .build());
	final FireBaseConfigSource configSource = new FireBaseConfigSource(this, firebaseRemoteConfig);
	airCon.init(new AirConConfiguration.Builder(this).enableXmlInjection(R.attr.class, configSource)
	                                                 .setJsonConverter(new GsonConverter())
	                                                 .setLogger(getLogger())
	                                                 .setLoggingEnabled(BuildConfig.DEBUG)
	                                                 .addConfigSource(configSource)
	                                                 .registerConfigType(new LabelConfigResolver())
	                                                 .build());
}
 
Example #27
Source File: MapActivity.java    From homeassist with Apache License 2.0 5 votes vote down vote up
private void setupAdSense() {
    Log.d("YouQi", "Map Adsense: " + ((FirebaseRemoteConfig.getInstance().getBoolean("adsense_map")) ? "Yes" : "No"));
    if (FirebaseRemoteConfig.getInstance().getBoolean("adsense_map")) {
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getString(R.string.banner_ad_unit_id_interstitial));
        mInterstitialAd.loadAd(CommonUtil.getAdRequest());
        mInterstitialAd.setAdListener(new AdListener() {
            public void onAdLoaded() {
                mInterstitialAd.show();
            }
        });
    }
}
 
Example #28
Source File: ApiFragment.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  frc = FirebaseRemoteConfig.getInstance();
  frc.setConfigSettings(
      new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build());

  firebaseInstallations = FirebaseApp.getInstance().get(FirebaseInstallationsApi.class);
}
 
Example #29
Source File: FirebaseRemoteConfigValueImpl.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public double asDouble() {
  if (source == FirebaseRemoteConfig.VALUE_SOURCE_STATIC) {
    return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
  }

  String valueAsString = asTrimmedString();
  try {
    return Double.valueOf(valueAsString);
  } catch (NumberFormatException e) {
    throw new IllegalArgumentException(
        String.format(ILLEGAL_ARGUMENT_STRING_FORMAT, valueAsString, "double"), e);
  }
}
 
Example #30
Source File: FirebaseRemoteConfigValueImpl.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public String asString() {
  if (source == FirebaseRemoteConfig.VALUE_SOURCE_STATIC) {
    return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_STRING;
  }

  throwIfNullValue();
  return value;
}