当前位置: 代码迷 >> Android >> android由应用包名失去该应用的默认启动类
  详细解决方案

android由应用包名失去该应用的默认启动类

热度:106   发布时间:2016-04-27 23:04:56.0
android由应用包名得到该应用的默认启动类
    /**     * get the launcher activity class full name of an application by the package name     *      * @param context     *            the context of current application     * @param packageName     *            the package name of the application (it can be any application)     * @return     */    public static String getLauncherActivityNameByPackageName(Context context, String packageName) {        String className = null;        Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);//android.intent.action.MAIN        resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);//android.intent.category.LAUNCHER        resolveIntent.setPackage(packageName);        List<ResolveInfo> resolveinfoList = context.getPackageManager().queryIntentActivities(resolveIntent, 0);        ResolveInfo resolveinfo = resolveinfoList.iterator().next();        if (resolveinfo != null) {            className = resolveinfo.activityInfo.name;        }        return className;    }

?该方法可以通过某个应用的包名找到该应用中的默认启动类

        <activity            android:name="com.fly.aty.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>

?如上,将AndroidManifest.xml中的包名传入第二个参数则可以得到com.fly.aty.MainActivity

  相关解决方案