Using @string for android: permissions in ContentProvider

I have a ContentProvider in my manifest, when I define them completely with hard-coded strings, it works. For example.

<provider android:name="com.myprovider" android:authorities="com.myprovider"/> 

It works fine, however ContentProviders are in a library that is used by several projects, and I don't want permission conflicts, so I tried the following.

 <provider android:name="com.myprovider" android:authorities="@string/myProviderAuthority"> 

Thus, I should be able to define all my permissions in one strings.xml file and not have conflicts between applications, since I should be able to change them using the application resource override system.

However, it seems that when I try to build using @string, it gives me the wrong manifest error and says: "The provider does not make INCUDE (yes, it says INCUDE) a tribute to power"

Can I use the resource string to pay tribute to power, I feel sick every time I need to maintain constants in two places. Conflicts with privileges can be difficult to grasp at our QA department, and I don’t want something to be out of sync, or it can be confusing. Anyone have any ideas why my code is not working?

+17
android android-contentprovider
Jun 23 '11 at 23:24
source share
2 answers

I ran into a similar problem, but with the android:versionCode . When I tried to determine the version code in resources and use the link to it in the Android Market manifest, I even forbade me to publish the application. The reason for this behavior was quite simple. Resources may vary depending on the current configuration, and this value should be the same anyway.

This is probably the reason why content providers with links to sources do not work. And it seems to me that it is not recommended to use such a link, because there is no guarantee that the only value for the resource of authority in the application. I understand that you can be careful enough to save one instance of this resource, but there is no special compiler or system for this, so it cannot be trusted.

+11
Jul 12 '11 at 20:25
source share

Many manifest attributes cannot be specified as a string reference - they must be specified as explicit string values.

The code that parses the manifest is in: frameworks / base / core / java / android / content / pm / PackageParser.java. This class calls, among other things, getNonConfigurationString () and getNonResourceString () (which are implemented in: frameworks / base / core / java / android / content / res / TypedArray.java).

getNonConfigurationString () describes itself as:

 Retrieve the string value of an attribute that is not allowed to change with the given configurations. 

getNonResourceString () describes itself as:

 Retrieve the string value for an attribute, but only if that string comes from an immediate value in an XML file. That is, this does not allow references to string resources, string attributes, or conversions from other types. As such, this method will only return strings that come from attributes in an XML file. 

The following are manifest attributes that PackageParser does not allow retrieval from resources or from different configurations.

These attributes are defined in com.android.internal.R.styleable. The attribute name of the manifest.xml element is usually the part of the name after the last '_' in the formal name. For example, the android: authority attribute in an element in manifest.xml is AndroidManifestProvider_authorities or com.android.internal.R.styleable.AndroidManifestProvider_authorities. (The number in the attribute name lists below is the line number of the corresponding code in Version 4.1.1 PackageParser.java)

Attributes read by getNonConfigurationString:

 917: AndroidManifest_versionName 922: AndroidManifest_sharedUserId 2057: AndroidManifestActivity_parentActivityName 2071: AndroidManifestActivity_permission 2079: AndroidManifestActivity_taskAffinity 2247: AndroidManifestActivityAlias_targetActivity 2330: AndroidManifestActivityAlias_permission 2336: AndroidManifestActivityAlias_parentActivityName 1672: AndroidManifestApplication_name 1683: AndroidManifestApplication_manageSpaceActivity 1697: AndroidManifestApplication_backupAgent 1795: AndroidManifestApplication_permission 1800: AndroidManifestApplication_taskAffinity 1815: AndroidManifestApplication_process 3005: AndroidManifestData_mimeType 3017: AndroidManifestData_scheme 3023: AndroidManifestData_host 3025: AndroidManifestData_port 3031: AndroidManifestData_path 3037: AndroidManifestData_pathPrefix 3043: AndroidManifestData_pathPattern 2527: AndroidManifestGrantUriPermission_path 2533: AndroidManifestGrantUriPermission_pathPrefix 2539: AndroidManifestGrantUriPermission_pathPattern 2579: AndroidManifestPathPermission_permission 2581: AndroidManifestPathPermission_readPermission 2586: AndroidManifestPathPermission_writePermission 2615: AndroidManifestPathPermission_path 2622: AndroidManifestPathPermission_pathPrefix 2629: AndroidManifestPathPermission_pathPattern 2434: AndroidManifestProvider_authorities 2441: AndroidManifestProvider_permission 2443: AndroidManifestProvider_readPermission 2454: AndroidManifestProvider_writePermission 2713: AndroidManifestService_permission 2832: AndroidManifestMetaData_name 1225: AndroidManifestOriginalPackage_name 1981: (parsePackageItemInfo -- I can't tell list of all names) 3258: (Component constructor args.nameres -- I can't tell list of all names) 

Attributes read by getNonResourceString:

 1806: AndroidManifestApplication_taskAffinity 1821: AndroidManifestApplication_process 1632: AndroidManifestInstrumentation_targetPackage 2891: AndroidManifestPackageVerifier_name 2894: AndroidManifestPackageVerifier_publicKey 1512: AndroidManifestPermission_permissionGroup 1200: AndroidManifestProtectedBroadcast_name 1927: AndroidManifestUsesLibrary_name 1054: AndroidManifestUsesFeature_name 1004: AndroidManifestUsesPermission_name 3308: (Component constructor args.processRes -- I can't tell list of all names) 

Thus, many attributes in the manifest.xml file must be specified as explicit string values ​​(i.e. in quotation marks), and not string references in strings.xml.

+6
03 Sep '14 at 16:57
source share



All Articles