アイコンのない小さなアプリをいくつか作成しましたが、これらは Android のアプリ メニューでユーザーが直接起動することはできません。それに点を付けるために、アプリのインテントフィルター部分を削除しました:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
ここで、これらの小さなアプリを大きなアプリから開始したいと思います (すべての小さなアプリを一覧表示する listView があります)。ユーザーがいずれかのアプリをクリックすると、対応するアプリのアクティビティが開始されます。しかし、小さなアプリの packageName でそれを行うと、何も起こりません。
ユーザーには見えず、大きなアプリからのみ起動する小さなアプリをたくさん用意することで、このモジュール性を維持したいと思っています。
可能であればどのようにすればよいでしょうか。
ありがとう
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);
}
}
}