Android Tutorial Manifest Editor

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:

SS-2012-01-08_12.46.34.png


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:
SS-2012-01-08_12.58.24.png


The result is that this text is added under the 'application' element:
SS-2012-01-08_12.59.27.png


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:

ilan

Expert
Licensed User
Longtime User
error: String types not allowed

hi

i try to add ADMOB to my app, i followed the instruction and i get an error massage:

B4X:
Compiling code.                         0.75
Compiling layouts code.                 0.05
Generating R file.                      Error
AndroidManifest.xml:20: error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').

something in the menifest editor is wrong

this is how it looks like in my mnifst editor:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetActivityAttribute(memory, android:screenOrientation, "landscape")
'Admob
AddApplicationText(
<activity android:name="com.google.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)
'End of default text.


what am i doing wrong?

thanx
 
Last edited:

frederick

New Member
Licensed User
Longtime User
How use Manifest Editor

Thank you for all response Erel Uziel.

I use AddApplicationText() to write this code in AndroidManifest.xml



<receiver android:name="com.pushnotifications.GCMReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="<your_package_name_application>"/>
</intent-filter>
</receiver>

but it return error

Can you help me to write this code with Manifest editor or give me the technique to write it.

Best regards
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that there is a tutorial about GCM here: Android push notification (GCM) framework and tutorial

AddApplicationText adds the given text to the <application> node. This is the place for activities, services and receivers. Which error do you get?

You can open AndroidManifest.xml after you compile to see the result of the manifest editor.
 

frederick

New Member
Licensed User
Longtime User
Help for Manifest Editor

Salut


I user AddPermission() to write permission in androidmanifest.xml

the result il look like this

<uses-permission android:name="com.starapplication.test_sdk_starapp.permission.C2D_MESSAGE" />

I want know how return result like this :
<permission android:name="com.starapplication.test_sdk_starapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
 

Turbo3

Active Member
Licensed User
Longtime User
My app optionally uses GPS. What do I add to the manifest to reflect that so Play Store does not exclude non-GPS devices from installing my app.

Will this do it?
B4X:
AddManifestText(<uses-feature android:name="android.hardware.location" android:required="false"/>)

Also what if any changes to my code are necessary to support optional GPS? I have statements like this in Activity_Create
If FirstTime Then GPS1.Initialize("GPS")

Whats going to happen when that gets executed and there is no GPS on the device?
 

Turbo3

Active Member
Licensed User
Longtime User
That did not work. On my Developer Console for the app under Required permissions still lists
  • android.permission.ACCESS_FINE_LOCATION
and under features lists
  • android.hardware.location.GPS

The device I am trying to allow my app to run on (iRiver INSIGNIA NS-14T002) is still listed as "Unsupported".

Here is the current Manifest:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddManifestText(<uses-feature android:name="android.hardware.location" android:required="false"/>)
AddActivityText(main, <intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" /></intent-filter>)

AddApplicationText( <uses-library android:required="false" name="com.sec.android.app.multiwindow"> </uses-library>
    <meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
    <meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632.0dip" />
    <meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598.0dip" />
    <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632.0dip" />
    <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598.0dip"
 

Turbo3

Active Member
Licensed User
Longtime User
Added line but nothing changed.

Could android.permission.ACCESS_FINE_LOCATION be the problem? Is there a way to make that not required?
 

jalle007

Active Member
Licensed User
Longtime User
Need to add two lines to manifest for LEadbolt to work

<receiver android:name="com.jalle.HumanitarniTelefon.ReEngagement" />
<service android:name="com.jalle.HumanitarniTelefon.ReEngagementService" />

when I do it like this

AddReceiverText(Main, <receiver android:name="com.jalle.HumanitarniTelefon.ReEngagement" />)
AddServiceText(Main, <service android:name="com.jalle.HumanitarniTelefon.ReEngagementService" />)

I got error "Module: main_br not found."
Why is "_br" added and what is the correct usage of these two commands ?
 

Johan Schoeman

Expert
Licensed User
Longtime User
I have the below statement in the manifest file of a project. How do I change the color of the text ("This is a project") of this label, centre it, and make it bold by adding additional statements to the manifest file? Have tried a trillion ways but it stays black text on a white background.

SetApplicationAttribute(android:label, "This is a project")
 

leitor79

Active Member
Licensed User
Longtime User
Hi,

I also would like to remove my app from the launcher list. I've used the code provided by NJDude here and it worked. But, my app is a service configured for starting at boot. And I've noticed the app is not starting after boot.

I've read here somewhere that a service configured for starting at boot requires to be manually opened before it can start at boot. But with the manifest edition to remove it from the launcher I can't start the app (and the "open" button after installing it is disabled).

So, is it impossible to start at service at boot if it's configured to be hidden on the launcher?


Regards,
 

Roy Raymundo

Member
Licensed User
Longtime User
I am using B4A version 4.30. Whenever I click New in File menu, this is the manifest that I get:

<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")

When I look at this website:
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
The only "5" that I see in the table is the Platform Level and the only "14" that I see is the API level. But according to the table (in the website that I include) Android 5.0 is API level 21. Kindly explain this android:minSdkVersion and android:targetSdkVersion of the manifest. Thanks a lot.
 
Top