Search code examples
huawei-mobile-serviceshuawei-push-notification

Huawei HMS initialize without Json file


Is it possible to initialize HMS without a agconnect-services.json and provide the keys at runtime?

Using a similar service (Fcm) we can initialize an app:

val builder = FirebaseOptions.Builder()
          .setApiKey(apiKey)
          .setGcmSenderId(senderId)
          .setProjectId(project)
          .setApplicationId(appId)
FirebaseApp.initializeApp(context, builder.build())

Therefore, you can use it without need of a json file to be parsed.

Is there a similar solution for this using HMS and AppGallery?

BTW, I'm trying to implement PushKit


Solution

  • Update:

    • Push Kit

    You can add the following code in your manifest file:

    <meta-data        
        android:name="com.huawei.hms.client.appid"        
        <!-- Replace value xxx with the actual appid.-->         
        android:value="appid=xxx">         
    </meta-data>
    

    Currently, HMS does not provide a unified solution for code-based initialization. However, some kits support code-based initialization.

    MapsInitializer.setApiKey("Your API Key");

    SearchService searchService = SearchServiceFactory.create(this, "API key");

    MLApplication.getInstance().setApiKey("your ApiKey");

    If you use only these kits, you do not need to integrate the JSON file. Instead, you can complete code-based initialization through the API key.

    We will analyze and discuss your requirement for a unified code-based initialization solution and reply to you as soon as possible.