Reputation: 242
I created some little apps without icon and which are not launchable by the user directly in the app menu of Android. To dot that, i deleted the intent-filter part of the apps :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Now, i want to start these little apps from a big one (i have a listView listing all the little apps). When the user click on one of the apps, i start the activity of the corresponding app. But when i do that with the packageName of the little app, nothing happen.
I really want to keep this modularity by having a lot of little apps which are invisible for the user and only start it from a big app.
How can i do that if it's possible.
Thanks
public class MainActivity extends ListActivity {
/**
* This class describes an individual SoftFunction (the function title, and the activity class that
* demonstrates this function).
*/
private class SoftFunction {
private CharSequence title;
private String packageName;
public SoftFunction(int titleResId, int appPackageResId) {
this.title = getResources().getString(titleResId);
this.packageName = getResources().getString(appPackageResId);
}
@Override
public String toString() {
return title.toString();
}
}
/**
* The collection of all Soft Functions in the app. This gets instantiated in {@link
* #onCreate(android.os.Bundle)} because the {@link Sample} constructor needs access to {@link
* android.content.res.Resources}.
*/
private static SoftFunction[] mSoftFunctions;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Instantiate the list of samples.
mSoftFunctions = new SoftFunction[]{
new SoftFunction(R.string.title_app_test1, R.string.app_test1_package_name),
new SoftFunction(R.string.title_app_test2, R.string.app_test2_package_name),
new SoftFunction(R.string.title_app_test3, R.string.app_test3_package_name),
new SoftFunction(R.string.title_app_test4, R.string.app_test4_package_name),
};
setListAdapter(new ArrayAdapter<SoftFunction>(this,
android.R.layout.simple_list_item_1,
android.R.id.text1,
mSoftFunctions));
}
@Override
protected void onListItemClick(ListView listView, View view, int position, long id) {
// Launch the sample associated with this list position.
Intent i = getPackageManager().getLaunchIntentForPackage(mSoftFunctions[position].packageName);
if (i != null)
{
startActivity(i);
}
}
}
Upvotes: 0
Views: 358
Reputation: 2664
You have to set android:exported="true" for your "little app" activities. This is because by default activities without intent filter(s) are not exported.
Like this:
<activity
android:name=".YourActivity"
...
android:exported="true" />
Then you can launch this activity from external apps using package name and activity name.
Intent intent=new Intent();
intent.setComponent(new ComponentName("com.your.package.name", "com.your.package.name.YourActivity"));
startActivity(intent);
Upvotes: 1