Android应用中的用户可配置Firebase帐户

时间:2017-06-20 09:19:15

标签: android firebase firebase-cloud-messaging

将Firebase Messaging添加到应用程序的默认方法是在应用程序根文件夹中放置google-services.json配置。此帐户是开发人员的帐户,并且已修复,一旦应用程序发布,就无法更改。

是否可以允许用户从商店下载应用,配置自己的Firebase帐户并将应用链接到自己的消息传递基础架构?

1 个答案:

答案 0 :(得分:1)

当您在项目中加入google-services.json时,该文件中的信息会在google-services gradle插件的编译时刻录到您的APK中。

但您也可以使用您在代码中直接提供的值初始化FirebaseApp实例。请参阅我的回答中的示例:How to connect to more than one firebase database from an android Appthis section of the Firebase documentation

// Manually configure Firebase Options
FirebaseOptions options = new FirebaseOptions.Builder()
    .setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics.
    .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") // Required for Auth.
    .setDatabaseUrl("https://myproject.firebaseio.com") // Required for RTDB.
    .build();
FirebaseApp app = FirebaseApp.initializeApp(getApplicationContext(), options);
FirebaseDatabase database = FirebaseDatabase.getInstance(app);

忽略多个项目的提及"在链接中 - 虽然这是需要此代码的更常见原因,但它也可以满足您的需求。