Disable Firebase crash reporting - android

I have decided to include the Firebase Crash API 9.0.1 into my Android app.
At the moment everything is working fine. Now I want to give my users the opportunity to disable, that Firebase is sending the Crash reports automatically.
Firebase Analytics can be disabled with this code snippet
FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(false);
Does anyone of you know a similar way to disable crash reporting?
Many thanks

Sorry for short answer but currently there is no official support for this.
EDIT: 30/10/2017
Now it is possible to enable/disable at build time adding in the AndroidManifest.xml:
<meta-data android:name="firebase_crash_collection_enabled" android:value="false" />
or runtime using:
FirebaseCrash.enableCrash(true|false);
More info here.

Yes it is possible now. Check this,
Disable Crash Reporting
Simply add the below line to your code in the first activity or even better in the Application class.
FirebaseCrash.setCrashCollectionEnabled(false);
To enable,
FirebaseCrash.setCrashCollectionEnabled(true);
This is really helpful when we have multiple build types such as Debug, Release etc.

You can find the instructions on the page:
https://firebase.google.com/support/guides/disable-analytics
Disable Analytics collection on Android
Temporarily disable collection
If you wish to temporarily disable Analytics collection, such as to get end-user consent before collecting data, you can set the value of firebase_analytics_collection_enabled to false in your app's AndroidManifest.xml in the application tag. For example:
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
To re-enable collection, such as after an end-user provides consent, call the setAnalyticsCollectionEnabled() method of the FirebaseAnalytics class. For example:
setAnalyticsCollectionEnabled(true);
If you need to suspend collection again for any reason, you can call
setAnalyticsCollectionEnabled(false);
and collection is suspended until you re-enable it.
Permanently deactivate collection
If you need to deactivate Analytics collection permanently in a version of your app, set firebase_analytics_collection_deactivated to true in your app's AndroidManifest.xml in the application tag. For example:
<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />

Related

Crashlytics sendUnsentReports() doesn't work even with FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false)

I need to send my reports right after the errors happens, but Crashlytics only send them when i restart the app.
I tried to follow the documentation and implement this in different ways, but everytime it seems to lead to the same outcome, which is that Crashlytics only send the reports after i restart the app. I get that this is the expected behavior, but it is completely useless for my app's purposes.
main.dart
...
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
...
AndroidManifest.xml
...
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
...
firebase_util.dart
...
await FirebaseCrashlytics.instance
.recordError(error, stackTrace, printDetails: true)
.then((value) async => await FirebaseCrashlytics.instance.sendUnsentReports());
...
What am i doing wrong?
The Android SDK will try to send the crash report after it happens, if you are on the latest Crashlytics SDK version this should be the case.
But in iOS, unfortunately, this will happen only after restarting the app. As far as I know, this is to avoid issues where the app gets closed while making network requests.
In relation to setCrashlyticsCollectionEnabled(false), this is intended for giving users more control of their data. You would set this to false in the manifest (for Android) or in the Info.plist (for iOS) to prevent Crashlytics from sending crash data. This explains why crashes not were being sent when calling:
FirebaseCrashlytics.instance.sendUnsentReports()
Then you could ask the user for their consent and if they do, you can set this value to true with:
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true)
After doing this, Crashlytics will start collecting and sending crash reports. But it will follow the process from above.

Prevent network requests from Facebook Android SDK

The Android Facebook SDK is always making a network request to graph.facebook.com when calling FacebookSdk.sdkInitialize(context) even if nothing of the SDK has been used yet.
So if we're initializing it in the Application.onCreate() there will always be at least one network request. Even if the setting is as follows:
<meta-data
android:name="com.facebook.sdk.AutoLogAppEventsEnabled"
android:value="false" />
We've took a closer look at this because a user complained that he is not using the Facebook Login (which is why we have the Facebook SDK in the first place) and still there is "user data" transferred to Facebook. In times of GDPR and suspicious users, this is a very unfavourable behaviour!
What we're doing now is calling FacebookSdk.sdkInitialize(context) only when the user wants to use the Facebook Login (at the time when the user clicks on the button). Additionally, we removed the meta-data for android:name="com.facebook.sdk.ApplicationId" from the AndroidManifest. This prevents the initial network request but then there is the following crash appearing in the CurrentAccessTokenExpirationBroadcastReceiver:
java.lang.RuntimeException: Unable to start receiver com.facebook.CurrentAccessTokenExpirationBroadcastReceiver: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
at com.facebook.internal.Validate.sdkInitialized(Validate.java:143)
at com.facebook.FacebookSdk.getApplicationContext(FacebookSdk.java:518)
at com.facebook.AccessTokenManager.getInstance(AccessTokenManager.java:86)
at com.facebook.CurrentAccessTokenExpirationBroadcastReceiver.onReceive(CurrentAccessTokenExpirationBroadcastReceiver.java:34)
Now there are several questions:
Why is Facebook still making a request at start? If they want to validate the auth token, they can do it as soon as the SDK is really used...
Does Facebook know and tolerate crashes when sdkInitialize() is not called? Because I fear when this NullPointerException is removed there will be other crashes...
Most important: Are there any other ways to prevent network requests from the Facebook SDK when its features are not used?
I have noticed that the Facebook SDK (at least in version 4.33) adds a provider (com.facebook.internal.FacebookInitProvider) in the manifest of your app, which automatically calls FacebookSdk.sdkInitialize with the application context.
Even if you have added:
<meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled" android:value="false" />
in your manifest, at least 2 requests will be made to Facebook:
a graph request to get app settings
an Events request "fb_sdk_initialize" which logs all the Facebook frameworks that are included into your app
So to prevent these requests (that we don't want as long as the user didn't allow them (GDPR)), I think you did everything we need to do:
Do not add <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/> in the manifest
Add <meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled" android:value="false"/> in the manifest
Only initialize Facebook SDK when you need it.
Like this for example:
FacebookSdk.setApplicationId(<context>.getString(R.string.facebook_app_id));
FacebookSdk.sdkInitialize(<context>);
AppEventsLogger logger = AppEventsLogger.newLogger(<context>); // I don't use FB Login for my project but app events.
But regarding your crash, I don't know why it happens since it seems that the broadcast "com.facebook.sdk.ACTION_CURRENT_ACCESS_TOKEN_CHANGED" is sent locally.
Nevertheless, I think you can prevent it by adding this to your manifest:
<provider
android:name="com.facebook.internal.FacebookInitProvider"
tools:node="remove" />
<receiver
android:name="com.facebook.CurrentAccessTokenExpirationBroadcastReceiver"
tools:node="remove" />
However, doing this may have bad consequences with the use of Facebook SDK and I think you will have to provide (and register in your manifest) your own BroadcastReceiver:
public class CustomCurrentAccessTokenExpirationBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (AccessTokenManager.ACTION_CURRENT_ACCESS_TOKEN_CHANGED.equals(intent.getAction())) {
new CurrentAccessTokenExpirationBroadcastReceiver().onReceive(context, intent); // Call it only if you have initialized the Facebook SDK!
}
}
}
According to Facebook Support,
If you would like to temporarily disable automatic events collection, such as to get end-user consent before collecting data, you can set the value of AutoLogAppEventsEnabled to false in the app's AndroidManifest.xml in the application tag.
For example:
<meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled" android:value="false"/>
To re-enable collection, such as after an end-user provides consent, call the setAutoLogAppEventsEnabled() method of the FacebookSDK class.
For example: setAutoLogAppEventsEnabled(true);
If you need to suspend collection again for any reason, you can call setAutoLogAppEventsEnabled(false); and collection will be suspended until re-enabling it.

Android wear not uploading data to Firebase

Instead of using the Data Layer and sending the data to phone, and uploading it from there, I simply wrote this code under a button:
Firebase ref = new Firebase("https://poponfa-8a11a.firebaseio.com/");
ref.child("lol").setValue("lol");
But for some strange reason, it usually suddenly stops working, pressing the button uploads nothing to firebase even though the phone is connected to the watch and internet. My question is, why is this behaviour occurring and how do I go about uploading directly from Wear, as I don't want to keep services running in the mobile App.
Haven't tried this personally, but you may want to try Identifying your Wear app as standalone.
Add the following in your Android Manifest file:
<application>
...
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
...
</application>
With this, a watch app can be considered as one of the following:
Completely independent of a phone app
Semi-independent (a phone app is not required and would provide only
optional features)
Dependent on a phone app
Then, you can proceed with saving data directly from your Wear.
See Read and Write Data on Android for more information.

How to opt out from Facebook SDK event logging?

I'm using Facebook App Events tracking for Android, but I have no idea how to disable tracking when a user wants to opt out! Does anyone know how to do that?
The documentation says:
We recommend that you use our SDK tools to offer the opt-out.
But they don't actually describe it anywhere. Classic Facebook move.
EDIT:
Now with the GDPR being in effect for so long, they still don't have any way to disable all tracking until the user consents, do they?
After the documentation was updated it seems the new way to go is a combination of disabling
<meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled"
android:value="false"/>
<meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled"
android:value="false"/>
<meta-data android:name="com.facebook.sdk.AutoInitEnabled"
android:value="false"/> <!--OPTIONAL-->
And at runtime to opt in call:
FacebookSdk.setAutoLogAppEventsEnabled(true)
FacebookSdk.setAdvertiserIDCollectionEnabled(true)
// OPTIONALLY the following line if AutoInitEnabled is set to false in manifest:
FacebookSdk.setAutoInitEnabled(true) // automatically calls FacebookSdk.fullyInitialize() under the hood
Right now I don't see when it would be good to disable (and later enable) auto init, maybe someone else might have an idea here.
Don't know about per User, but you can opt put from Facebook SDK event logging:
Add this int your Android.Manifest.xml:
<meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled"
android:value="false"/>
The opt-out they are talking about is described in the heading below: https://developers.facebook.com/docs/app-events/android#setlimiteventusage
You can call AppEventsLogger.setLimitEventUsage(this, true); to "opt-out" (at least limit) how the events logged are used.

Cannot see Crittercism app crashes on Android

I use crittercism for my app. Here is what i do to initialize Crittercism:
I only use the following permission:
<uses-permission android:name="android.permission.INTERNET"/>
and i initialize Crittercism like the following:
Crittercism.initialize(getApplicationContext(), "MY_APP_ID");
I do nothing else.
I can see some information about app installs etc, but i cannot see crash reports. I do the following when i click a button in my app and deliberately crash the app:
public void onClick(){
Integer i = null;
i++;
}
But i cannot see the crash report of this situation. Can anyone tell me why? Do i need to add mappings.txt file etc.?
Thanks
As the official Crittercism documentation says, you need more permissions.
Add the following permissions to your app’s AndroidManifest.xml file.
INTERNET
Required. Used to report data to Crittercism.
ACCESS_NETWORK_STATE
Optional. Allows providing network connectivity information such as carrier and network type.
READ_LOGS
Optional. Allows collecting logcat data to be attached to crashes and handled exceptions.
GET_TASKS
Optional. Allows augmenting crash reports with information on the activity running during a crash.
Documentation
You probably need "GET_TASKS" in order to have crash reports.
I found the problem.
It seems that in the developer console, the platform was set to IOS, i changed it to Android and i can see crash reports now.

Categories

Resources