Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a resource string for a package name?

Is something like this possible?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="@string/package_name"
      android:versionCode="1"
      android:versionName="@string/version_name">

The code above gives me an error:

C:\android-sdk\tools\ant\build.xml:539: Application package '@string/package_name' must have a minimum of 2 segments.

My strings are defined in res/strings.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My app</string>
    <string name="version_name">1.00</string>
    <string name="package_name">com.mycompany.myapp</string>

If I replace @string/package_name with the name of the package, android:versionName seems to be set correctly.
So the question is why package name doesn't work while android:versionName works?

Edit: Is there any way to use a package name specified in external file?

like image 570
Lev Avatar asked Mar 13 '13 02:03

Lev


People also ask

Is a resource file used to hold name value pairs of strings?

xml is a resource file used to hold name/value pairs of strings.

How do we define a string resource?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.

Why should you use string resources instead of hard coded strings in your apps?

It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).

Which of the format string is not valid?

Format string XXX is not a valid format string so it should not be passed to String.


1 Answers

AFAIK, you may only access XML resources using the @resource/name format for attributes defined in the android xmlns (http://schemas.android.com/apk/res/android).

As package is not defined in the android schema, it cannot access resources that way, while versionName can.

like image 131
Raghav Sood Avatar answered Oct 30 '22 23:10

Raghav Sood