MyException - 我的异常网
当前位置: 我的异常网 » 操作系统 » 2011.07.06(二)——— android apiDemos 之 Resol

2011.07.06(二)——— android apiDemos 之 ResolveInfo

www.MyException.Cn,网友分享于:2012-06-30 17:20:13   浏览:10次
2011.07.06(2)——— android apiDemos 之 ResolveInfo
2011.07.06(2)——— android apiDemos 之 ResolveInfo

参考:http://maxuefeng.blog.51cto.com/1876326/528680

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.apis">

    <application android:name="ApiDemosApplication"
            android:label="@string/activity_sample_code"
            android:icon="@drawable/app_sample_code" >

        <activity android:name="ApiDemos">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".app.HelloWorld" android:label="@string/activity_hello_world">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

        <activity android:name=".app.DialogActivity"
                android:label="@string/activity_dialog"
                android:theme="@android:style/Theme.Dialog">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>



如上所示的一个ActionManifest.xml  则:
       
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_SAMPLE_CODE);

        PackageManager pm = getPackageManager();
        List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
        for (int i = 0; i < len; i++) {
            ResolveInfo info = list.get(i);
            CharSequence labelSeq = info.loadLabel(pm);
            System.out.println("===="+labelSeq.toString()+"===="+info.activityInfo.name+"=========="+info.activityInfo.applicationInfo.packageName);
        }



则 结果为:


=App/Activity/HelloWorld====com.example.android.apis.app.HelloWorld==========com.example.android.apis 
=App/Activity/Dialog====com.example.android.apis.app.DialogActivity==========com.example.android.apis

软件开发程序错误异常Exception Copyright © 2009-2015 MyException 版权所有