# How to use Google FireBase in Android?

The Post Created(Updated) On 05/6/2022，Please note the timeliness of the article!

The purpose of my reference to Firese here is mainly to detect how many users are using the product in question, using the free version of Firebase. See the official tutorials or stuck in some places, especially when it comes to detecting success. More fortunately, the Google team is still relatively reliable, consulting related issues can give timely feedback and advice.

# Use

• Download the configuration-related files according to the boot process, the operation flow is arranged quite clearly, just pay attention to the details.

• Here on the key point, that is, the need to also configure some relevant information in the code, this is not mentioned in the tutorial, I did not add here is not any effective detection, and finally added after the good.

...
public class GameActivity extends AppCompatActivity {

private FirebaseAnalytics mFirebaseAnalytics;

protected void onCreate(@Nullable Bundle savedInstanceState) {

// Obtain the FirebaseAnalytics instance.
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this). mFirebaseAnalytics.getInstance(this). mFirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.setAnalyticsCollectionEnabled(true);
Bundle bundle = new Bundle();
bundle.putString("start", "yes");
mFirebaseAnalytics.logEvent("share", bundle);

...
}
}


## Configuration

• Go to the adb directory, usually under the path of your configured SDK, e.g. windwos is
D:\SoftWare\Android\SDK\platform-tools

• Enable debug mode, and replace package_name with your own application package_name.
adb shell setprop debug.firebase.analytics.app package_name

• View the events in the Android Studio debug log.
adb shell setprop log.tag.FA VERBOSE
adb logcat -v time -s FA FA-SVC


• Debugging at the same time in the Firebase corresponding APP DebugView to see if the relevant logs are received, if they can be received properly, it means that the configuration is correct. Sometimes there may be network problems and can not upload, pay attention to the logs to operate.

• disable debug mode
adb shell setprop debug.firebase.analytics.app .none.


## No data

• Is the configuration and related code added, and is the app installed correctly on the phone or emulator?

• If the logs are similar to the following, then it’s a network environment problem that causes upload problems.

05-06 16:58:41.419 V/FA-SVC ( 9255): Uploading data. size: 794
05-06 16:58:44.123 V/FA-SVC ( 9255): Network upload failed. will retry later. code, error: 0, javax.net.ssl.SSLHandshakeException: Handshake failed
Handshake failed

cmd
05-06 16:55:14.770 V/FA-SVC ( 9255): Network upload failed. will retry later. code, error: 0, java.net.UnknownHostException: Unable to resolve host " app-measurement.com": No address associated with hostname
05-06 16:55:14.792 V/FA-SVC ( 9255): Upload scheduled in approximately ms: 1800978


# Reference

https://blog.emperinter.info/2022/05/06/how-to-use-google-firebase-in-android`