Dynamic Package Id for android plugin manifest code

Hello,

I have a 3rd party lib which uses their own push notification system and for that they expect the client to specify receivers and services in their manifest.

I can do this fine when I am building my enterprise app and get it to work, but for a plugin how would I go about dynamically giving the package name to the plugin manifest? The merge will happen on its own, so I can just leave the code itself in the plugin manifest I guess, but how would that {package id} be set

They require the following to be added in the app manifest when integrating the SDK, I need to do something for the plugin so this happens automatically, can someone point me to the docs for this or provide some general guidance. Thanks

        <receiver android:name=“com.testcompany.messaging.CloudMessagingReceiver” android:exported=“true” android:permission=“com.google.android.c2dm.permission.SEND” >

            <intent-filter>

                <action android:name=“com.testcompany.messaging.OPEN” />

                <action android:name=“com.google.android.c2dm.intent.RECEIVE” />

                <category android:name="{PACKAGE ID}" />

            </intent-filter>

        </receiver>

        <service android:name=“com.testcompany.messaging.CloudMessagingService” android:exported=“false” >

            <intent-filter>

                <action android:name=“com.google.android.c2dm.intent.RECEIVE” />

            </intent-filter>

        </service>

        <service android:name=“com.testcompany.messaging.CloudRegistrationService” android:exported=“false”>

        </service>

Anyone got any clues or ideas, must be a pretty common requirement for 3rd party plugin integrations using push ?

For the plugin build, I need to somehow replace the {PACKAGE ID} above with the Corona app name that the users have selected from the Corona build screen automatically as normal Corona users don’t have access. 

Based on the information on: https://docs.coronalabs.com/native/plugin/submission.html

It seems I can provide manifest changes expected,

applicationChildElements =   {   – Example in the comment block   --[==[  [[   <activity android:name=“com.mycompany.MyActivity”   android:configChanges=“keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize”/>]],   --]==]   },

but in my case I have to insert the App package id into the manifest for the device to be registered for 3rd party push notification service.

Thanks

Set the category name to “@USER_ACTIVITY_PACKAGE@” like this…

\<category android:name="@USER\_ACTIVITY\_PACKAGE@"/\>

And right, you need to create a “metadata.lua” file to inject these elements into the APK’s AndroidManifest.xml file.  Yours should look something like this…

local metadata = { plugin = { format = "jar", manifest = { permissions = { { name = ".permission.C2D\_MESSAGE", protectionLevel = "signature" }, }, -- You should double check what permissions are required by this library. usesPermissions = { "android.permission.INTERNET", "android.permission.GET\_ACCOUNTS", "com.google.android.c2dm.permission.RECEIVE", ".permission.C2D\_MESSAGE", }, applicationChildElements = { [[\<receiver android:name="com.testcompany.messaging.CloudMessagingReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"\> \<intent-filter\> \<action android:name="com.testcompany.messaging.OPEN"/\> \<action android:name="com.google.android.c2dm.intent.RECEIVE"/\> \<category android:name="@USER\_ACTIVITY\_PACKAGE@"/\> \</intent-filter\> \</receiver\>]], [[\<service android:name="com.testcompany.messaging.CloudMessagingService" android:exported="false"\> \<intent-filter\> \<action android:name="com.google.android.c2dm.intent.RECEIVE"/\> \</intent-filter\> \</service\>]], [[\<service android:name="com.testcompany.messaging.CloudRegistrationService" android:exported="false"/\>]], }, }, }, }

Also note that the permission names above having a leading period ‘.’ (ex: “.permission.C2D_MESSAGE”) will have the package name injected in front of it.  This is a Corona build system feature and not a Google feature.

I hope this helps!

Perfect exactly what I was after, thanks Joshua

Anyone got any clues or ideas, must be a pretty common requirement for 3rd party plugin integrations using push ?

For the plugin build, I need to somehow replace the {PACKAGE ID} above with the Corona app name that the users have selected from the Corona build screen automatically as normal Corona users don’t have access. 

Based on the information on: https://docs.coronalabs.com/native/plugin/submission.html

It seems I can provide manifest changes expected,

applicationChildElements =   {   – Example in the comment block   --[==[  [[   <activity android:name=“com.mycompany.MyActivity”   android:configChanges=“keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize”/>]],   --]==]   },

but in my case I have to insert the App package id into the manifest for the device to be registered for 3rd party push notification service.

Thanks

Set the category name to “@USER_ACTIVITY_PACKAGE@” like this…

\<category android:name="@USER\_ACTIVITY\_PACKAGE@"/\>

And right, you need to create a “metadata.lua” file to inject these elements into the APK’s AndroidManifest.xml file.  Yours should look something like this…

local metadata = { plugin = { format = "jar", manifest = { permissions = { { name = ".permission.C2D\_MESSAGE", protectionLevel = "signature" }, }, -- You should double check what permissions are required by this library. usesPermissions = { "android.permission.INTERNET", "android.permission.GET\_ACCOUNTS", "com.google.android.c2dm.permission.RECEIVE", ".permission.C2D\_MESSAGE", }, applicationChildElements = { [[\<receiver android:name="com.testcompany.messaging.CloudMessagingReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"\> \<intent-filter\> \<action android:name="com.testcompany.messaging.OPEN"/\> \<action android:name="com.google.android.c2dm.intent.RECEIVE"/\> \<category android:name="@USER\_ACTIVITY\_PACKAGE@"/\> \</intent-filter\> \</receiver\>]], [[\<service android:name="com.testcompany.messaging.CloudMessagingService" android:exported="false"\> \<intent-filter\> \<action android:name="com.google.android.c2dm.intent.RECEIVE"/\> \</intent-filter\> \</service\>]], [[\<service android:name="com.testcompany.messaging.CloudRegistrationService" android:exported="false"/\>]], }, }, }, }

Also note that the permission names above having a leading period ‘.’ (ex: “.permission.C2D_MESSAGE”) will have the package name injected in front of it.  This is a Corona build system feature and not a Google feature.

I hope this helps!

Perfect exactly what I was after, thanks Joshua