Android的自定义类别 [英] Android custom categories
问题描述
我有一个视图包含可用的应用程序的行为作为图标+文字对(台式机等)的应用程序的主屏幕。
I have a view as a main screen of the application which contains the available application's actions as icon+text pairs ( desktop like).
我想找出什么编程仅在我AndroidManifest.xml中定义的活动
I want to find out programatically what are the activities defined ONLY in my AndroidManifest.xml
假设我有:
< activity android:name="example.mainActivity" android:label="mainActivity">
< intent-filter>
< action android:name="android.intent.action.MAIN" />
< category android:name="android.intent.category.LAUNCHER" />
< /intent-filter>
< /activity>
< activity android:name="example.activity1" android:label="Activity1">
< intent-filter>
< action android:name="android.intent.action.VIEW" />
< category android:name="example.custom.ACTIVITY" />
< /intent-filter>
< /activity>
< activity android:name="example.activity2" android:label="Activity2">
< intent-filter>
< action android:name="android.intent.action.VIEW" />
< category android:name="example.custom.ACTIVITY" />
< /intent-filter>
< /activity>
我想,在mainActivity到dinamically阅读活动1和活性2,因为当我添加Activity3例如,它会自动读取。
I want that in the mainActivity to dinamically read Activity1 and Activity2 because when i add Activity3 for example it will be automatically read.
意向意图=新的意图(android.intent.action.VIEW); intent.addCategory(example.custom.ACTIVITY); 名单解析= getPackageManager()queryIntentActivities(意向,0);。
Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("example.custom.ACTIVITY"); List resolves = getPackageManager().queryIntentActivities(intent, 0);
在做出决议列表我期望有两个定义的活动,所以我可以得到他们的标签和形象,创造图标在桌面
In the resolves list i expect to have the two defined activities so i can get their label and image and create the icon for the desktop
我认为这可以通过定义一个定制类来完成,example.custom.ACTIVITY,并在mainActivity使用packageManager.queryIntentActivities(意向意图,诠释标志),但它似乎并不奏效。
I thought that this could be done by defining a custom category, example.custom.ACTIVITY, and in the mainActivity use the packageManager.queryIntentActivities(Intent intent, int flags) but it doesn't seem to be working.
我真的想为code到dinamically发现在我的应用程序的安装活动。 你对如何做到这一点的任何想法吗? 谢谢
I really would like to code it to dinamically discover the installed activities in my application. Do you have any ideas on how to do this? Thank you
推荐答案
在我的应用我所定义的动作为android.intent.action.MAIN(而不是android.intent.action.VIEW),并检索可以作为你的预期:
In my app I defined the actions as "android.intent.action.MAIN" (not "android.intent.action.VIEW"), and the retrieval works as you expected:
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory("com.example.ACTIVITY");
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
PS,我曾经为com.example,因为榜样是不是一个好名字空间的例子,在你的清单包声明必须至少有两个段(见<一href="http://stackoverflow.com/questions/16107401/application-package-androidmanifest-xml-must-have-a-minimum-of-2-segments">here)
这篇关于Android的自定义类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!