英文:
Temporarily disable all services of Firebase before user accepts consent
问题
我有一个已经实现了Firebase的应用程序。我想在用户接受数据收集许可之前禁用与Firebase相关的所有内容。在Android文档中,我看到例如可以使用以下方式禁用Firebase Analytics:
setAnalyticsCollectionEnabled(false);
但如果我正在使用Firebase的更多服务呢?
是否有一种方法可以在用户接受数据收集许可之前禁用与Firebase相关的所有内容,以便任何Firebase服务都不会收集任何数据?
英文:
I have an app that has Firebase implemented. What I want is to disable everything related to Firebase before the user accepts the data collection consent. In android documentation I have seen that for example I can disable Firebase Analytics with:
setAnalyticsCollectionEnabled(false);
Okay, but what if I am using more services of Firebase?
Is there any way to disable everything related with Firebase so that any data is collected by any service of Firebase before the user has accepted the data collection consent?
答案1
得分: 1
没有适用于您尝试执行的操作的API。
最好的方法是在正确的时间之前根本不初始化Firebase。 未初始化的Firebase SDK在其任何产品中都不会执行任何操作。 您将不得不手动进行初始化,而不是从默认集成中获得的自动化初始化。
英文:
There is no API for what you're trying to do.
Your best bet is to simply not initialize Firebase at all until the time is right. An uninitialized Firebase SDK will do absolutely nothing in any of its products. You will have to instead do manual init and not the automated init that you get from a default integration.
答案2
得分: 0
更新,显然工作:
我已经按照“在Android上掌控您的Firebase初始化”文章的方法进行了操作:
https://firebase.blog/posts/2017/03/take-control-of-your-firebase-init-on/
我所做的事情:
我已经在我的根 AndroidManifest.xml 中添加了以下内容,以禁用自动提供程序合并,正如文章中所解释的那样:
<application>
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="${applicationId}.firebaseinitprovider"
tools:node="remove"
/>
</application>
之后,我手动初始化了Firebase:
在 OnCreate() 方法中:
FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
.setApplicationId("1:0123456789012:android:0123456789abcdef")
.setApiKey("your_api_key")
.setStorageBucket("your-app.appspot.com");
FirebaseApp.initializeApp(this, builder.build());
注意:我没有使用 .setDatabaseUrl("https://your-app.firebaseio.com")
,因为我没有使用数据库服务。
好的,这对我来说不起作用(由于提供程序现在没有合并(这是完全预期的),服务不起作用,但是初始化不起作用,我不知道为什么)
为了使它起作用,我做了以下操作,不知道为什么添加以下内容起作用:
我已经在构建器中添加了 .setProjectId
,现在它按预期工作。
英文:
Update apparently working:
I have followed "Take Control of Your Firebase Init on Android" article:
https://firebase.blog/posts/2017/03/take-control-of-your-firebase-init-on/
What I have done:
I have added to my root AndroidManifest.xml the following to disable automatic Provider merger as explained in the article:
<application
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="${applicationId}.firebaseinitprovider"
tools:node="remove"
/>
</application>
After this I have manually initialized Firebase:
In OnCreate() method:
FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
.setApplicationId("1:0123456789012:android:0123456789abcdef")
.setApiKey("your_api_key")
.setStorageBucket("your-app.appspot.com");
FirebaseApp.initializeApp(this, builder.build());
Note: I have not used.setDatabaseUrl("https://your-app.firebaseio.com") as I not use Database Service.
Okay, this was not working form me (services were not working due that the provider isn't merging now (this is totally expected), but initialization was not working and I din't know why)
What I have done to make it work and don't know why adding the following is working:
I have added .setProjectId
to the builder and now is working as expected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论