Specifying targetPackage for intent in the library project XML file

I have a library project that I use to create two applications: public and private for personal use, with several settings that are useless for most people. In this library project, I define PreferenceActivity (for API <Honeycomb) and some PreferenceFragments (for API> = Honeycomb) with preference headers using this guide: http://developer.android.com/guide/topics/ui/settings.html #BackCompatHeaders

To support older devices, I define this XML file as shown in the manual:

<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <Preference android:title="@string/base_de_donnees" android:summary="@string/summary_pref_restaurer_bdd_sd"> <intent android:targetPackage="com.me.app_lib" android:targetClass="com.me.app_lib.activities.preferences.SettingsActivity" android:action="com.me.app_lib.activities.preferences.SettingsActivity.ACTION_PREF_BDD" /> </Preference> <Preference android:title="@string/saisie" android:summary="@string/summary_pref_saisie"> <intent android:targetPackage="com.me.app_lib" android:targetClass="com.me.app_lib.activities.preferences.SettingsActivity" android:action="com.me.app_lib.activities.preferences.SettingsActivity.ACTION_PREF_SASISIE" /> </Preference> </PreferenceScreen> 

Where com.me.app_lib is the library project package that defines the SettingsActivity parameter. However, I get a failure when the intent is called from one of the child projects, because targetPackage does not match that for the child project. If I change com.me.app_lib to com.me.app_public (the package of one of the child projects), it works, but since I have two child projects, this is not an option.

Do I need to copy this file to each of the child projects and change only the targetPackage line, or is there a better option?

+4
source share
1 answer

In the end, I made the com.me.app_lib command as a resource string. The android: targetPackage attribute becomes:

 android:targetPackage="@string/package_activity_preferences" 

Then I can define a different value in both child projects for this line. This is not as clean as we would like, but at least I do not need to copy the same file to both child projects. TargetClass is part of my library project, so I don't need to change anything about it; The problem was only with the targetPackage attribute.

+3
source

All Articles