简体   繁体   中英

How to use dash and dot characters in android:name in AndroidManifest.xml?

For my Android app, I need to add the following property into <application> in AndroidManifest.xml:

<application android:name="de.myapp.My-App.de">

The name of the project is "My-App.de". I know that using dashes and dots here is no good idea but I can't change it. The product owner wants it called like this.

Since I get an error message, I simply escaped the dash with a "\\" character which leads to this name:

<application android:name="de.myapp.My\-App.de">

Is this correct? Must the very last dot be escaped too?

In your strings.xml under the res/values folder, you can add your app name like so:

<string name="app_name">de.myapp.My-App.de</string>

Then in your AndroidManifest.xml you can reference it:

<application android:name="@string/app_name">

This will allow your app name to have dashes.

Why not using android:label ?

Just a sidenote. If your client told you to use a plutonium keyboard instead of a regular keyboard, would you accept it? Sometimes (almost every time) we have to rid with clients that doesn't have the same background we do, specially when coming to Computer Science. If something can't be done (or shouldn't or whatever), you should convice your client. You can give them many reasons: the system is less secure or could be compromised, the application becomes unstable, what the client wants could be done in an easier to understand way, etc.

At least in my company, I am paid to develop AND to give advice, and even if I talk to a client, I tend to ensure they understand the implications of what they want and know what can't be done and what should be done instead.

Edit:

Some resources:

http://developer.android.com/guide/topics/manifest/application-element.html#nm

Name is a fully qualified name for an Application subclass . As you may know, classes aren't to be written with dashes. We are all aware that Android's naming convention is not the most accurate in the world, so problems like this always arise. Try adding to the already defined by default @string/app_name a dash. I am not in front of my Android projects, but it should work as well. If it doesn't, try enclosing the string with a CDATA markup:

<string name="app_name"><![CDATA[de.myapp.My-App.de]]></string>

This avoids xml escaping the text (which should not be necessary, but who knows).

I'm suggesting you to store your appname in the string.xml and encode the special character - (dash) and . (dot) to unicode you can refer the unicode in here -> http://jrgraphix.net/research/unicode_blocks.php?block=0

For example .My\-App\.de

<application android:name="de.myapp.My-App.de"> is not correct.

You just use

<application android:name="Package_name.Application_class_name">

Where name's of package and class must

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM