I am programming for Android 1.6, the following code works in 2.2 (API Level 5):
Intent intentChooser = Intent.createChooser(intent, "Choose between these programs");
Intent intentTest= new Intent(Intent.ACTION_VIEW);
....
Parcelable [] parcelable = new Parcelable [1];
parcelable[0] = new LabeledIntent(intentTest, "", "the text of the label", 0);
intentChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, parcelable);
activity.startActivity(intentChooser);
I don’t know if the parcelable can include another type of data (not LabeledIntent). That would be a possible solution.
I have tried to include the code of LabeledIntent in my project, I have found here:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/content/pm/LabeledIntent.java
but no success. That would be another question, how to include classes of later versions in older Android versions.
Any ideas?
The user Commonsware gave me the solution:
Android: how to code depending on the version of the API?
The solution was to create a proxy class, so that determining if the sdk was < than level 5, I instanced a class that did not include the LabeledIntent class, only available from 2.0 on.
The one thing one has to bear in mind is that you cannot instance any class that includes a reference to a package / class from a more modern sdk. So in fact, with the code below I never reference the class (LabeledIntentNew) that had the reference to LabeledIntent, if the sdk was < than 5.
That is the code:
To instance this class you do: