Basic4android v1.8 introduces a new tool named Manifest Editor.
Every Android application includes a file named AndroidManifest.xml.
This is an XML file that describes the application for the OS. It includes elements such as the application components (activities, services and receivers), icons, permissions and other required information.
You can see more information about this file here: The AndroidManifest.xml File | Android Developers
Basic4android compiler generates this file automatically. In most cases there is no need to change anything. However in some cases, especially when using third party libraries (ads for example), the developer is required to add some elements to the manifest file.
Until version 1.8 the solution was to mark the manifest file as read-only or check the "Do not write manifest file" option and prevent the compiler from recreating this file during compilation.
This however means that from now on, the developer needs to maintain the manifest file and update it when the project is updated.
The new manifest editor solves the above issue. It allows developers to add or modify elements in the manifest while also allowing the compiler to add the standard elements.
Choosing Project - Manifest Editor will open the editor:
As shown in the above screenshot the editor starts with several default elements.
You can modify these elements or add other elements as needed.
To make it easier to add multiline strings and strings that contain quote characters the manifest editor treats all characters between the open parenthesis and the closing parenthesis or comma (for commands with multiple parameters) as a single string.
Escaping end of string characters
If you need to write a string with a comma you should write two commas: ,,
The same thing is true for strings with closing parenthesis: ))
Editor commands
There are several types of commands: commands that add an additional text inside an element, commands that set the value of an attribute (replacing the old value if it already exists) and two other commands which will be discussed later.
List of commands
Add text commands
For example the AdMob library requires us to add an activity to the manifest file:
The result is that this text is added under the 'application' element:
Note that you can call 'add text' commands multiple times.
AddActivityText / AddServiceText / AddReceiverText - expect two parameters: component name and the text to add.
For example to use C2DM push framework you should add some text to the receiver. Note that a Service module in Basic4android is actually made of a native service and a native receiver. The name of the receiver is the same as the service module.
Other "add text" commands: AddApplicationText and AddManifestText. Both expect a single parameter which is the text to add.
Set attribute commands
For example the following command can be used to set the orientation of a specific activity:
Note that the attributes keys are case sensitive.
SetActivityAttribute / SetReceiverAttribute / SetServiceAttribute - expect three parameters: component name, attribute key and attribute value.
SetManifestAttribute / SetApplicationAttribute - expect two paramters: attribute key and attribute value.
Other commands
AddReplacement - this method allows you to declare a string that will be replaced with a second string. The compiler automatically adds the following declarations: $PACKAGE$ (replaced with the package name), $LABEL$ (replaced with the application label) and $ORIENTATION$ (replaced with the orientation value).
The string replacement happens as the last step. You can use it to delete other strings by replacing them with an empty string.
Syntax: AddReplacement (OldString, NewString)
AddPermission - Adds a permission if it doesn't already exist. You can also add permissions using AddApplicationText. The advantage of AddPermission is that it makes sure to only add each permission once.
Syntax: AddPermission (Permission)
Example: AddPermission (android.permission.INTERNET)
RemovePermission - Removes a permission. Same syntax as AddPermission.
CreateResource - Creates a XML resource file: https://www.b4x.com/android/forum/threads/new-feature-three-birds-with-one-stone.63127/#post-398974
Tips
- Deleting the whole text will restore the default text (after you reopen the manifest editor).
- As written at the beginning, in most cases you do not need to add anything to the manifest editor.
- Open AndroidManifest.xml to better understand how it is built.
- The "Do not modify manifest file" option is still available for backwards compatibility. It is recommended to use the new editor instead.
Every Android application includes a file named AndroidManifest.xml.
This is an XML file that describes the application for the OS. It includes elements such as the application components (activities, services and receivers), icons, permissions and other required information.
You can see more information about this file here: The AndroidManifest.xml File | Android Developers
Basic4android compiler generates this file automatically. In most cases there is no need to change anything. However in some cases, especially when using third party libraries (ads for example), the developer is required to add some elements to the manifest file.
Until version 1.8 the solution was to mark the manifest file as read-only or check the "Do not write manifest file" option and prevent the compiler from recreating this file during compilation.
This however means that from now on, the developer needs to maintain the manifest file and update it when the project is updated.
The new manifest editor solves the above issue. It allows developers to add or modify elements in the manifest while also allowing the compiler to add the standard elements.
Choosing Project - Manifest Editor will open the editor:
As shown in the above screenshot the editor starts with several default elements.
You can modify these elements or add other elements as needed.
To make it easier to add multiline strings and strings that contain quote characters the manifest editor treats all characters between the open parenthesis and the closing parenthesis or comma (for commands with multiple parameters) as a single string.
Escaping end of string characters
If you need to write a string with a comma you should write two commas: ,,
The same thing is true for strings with closing parenthesis: ))
Editor commands
There are several types of commands: commands that add an additional text inside an element, commands that set the value of an attribute (replacing the old value if it already exists) and two other commands which will be discussed later.
List of commands
Add text commands
For example the AdMob library requires us to add an activity to the manifest file:
The result is that this text is added under the 'application' element:
Note that you can call 'add text' commands multiple times.
AddActivityText / AddServiceText / AddReceiverText - expect two parameters: component name and the text to add.
For example to use C2DM push framework you should add some text to the receiver. Note that a Service module in Basic4android is actually made of a native service and a native receiver. The name of the receiver is the same as the service module.
AddReceiverText(PushService,
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="anywheresoftware.b4a.samples.push" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="anywheresoftware.b4a.samples.push" />
</intent-filter>)
Other "add text" commands: AddApplicationText and AddManifestText. Both expect a single parameter which is the text to add.
Set attribute commands
For example the following command can be used to set the orientation of a specific activity:
SetActivityAttribute(Main, android:screenOrientation, "portrait")
Note that the attributes keys are case sensitive.
SetActivityAttribute / SetReceiverAttribute / SetServiceAttribute - expect three parameters: component name, attribute key and attribute value.
SetManifestAttribute / SetApplicationAttribute - expect two paramters: attribute key and attribute value.
Other commands
AddReplacement - this method allows you to declare a string that will be replaced with a second string. The compiler automatically adds the following declarations: $PACKAGE$ (replaced with the package name), $LABEL$ (replaced with the application label) and $ORIENTATION$ (replaced with the orientation value).
The string replacement happens as the last step. You can use it to delete other strings by replacing them with an empty string.
Syntax: AddReplacement (OldString, NewString)
AddPermission - Adds a permission if it doesn't already exist. You can also add permissions using AddApplicationText. The advantage of AddPermission is that it makes sure to only add each permission once.
Syntax: AddPermission (Permission)
Example: AddPermission (android.permission.INTERNET)
RemovePermission - Removes a permission. Same syntax as AddPermission.
CreateResource - Creates a XML resource file: https://www.b4x.com/android/forum/threads/new-feature-three-birds-with-one-stone.63127/#post-398974
Tips
- Deleting the whole text will restore the default text (after you reopen the manifest editor).
- As written at the beginning, in most cases you do not need to add anything to the manifest editor.
- Open AndroidManifest.xml to better understand how it is built.
- The "Do not modify manifest file" option is still available for backwards compatibility. It is recommended to use the new editor instead.
Last edited: