获取启动activity的包名和类名,核心代码

List<PackageInfo>  packageinfos = getPackageManager().getInstalledPackages(
PackageManager.GET_UNINSTALLED_PACKAGES|PackageManager.GET_ACTIVITIES
);// PackageManager.GET_ACTIVITIES这一句是为了获得系统的activity,防止启动时,空指针异常

PackageInfo packageinfo = showpackage.get(position);
final String packageName = packageinfo.packageName;//获得包名,启动activity的一个参数,position一般指的是listview和gridview中的适配器中的一个参数

    final ActivityInfo appinfo=packageinfo.activities[0];//获得应用的第一个activity
String activityName=appinfo.name;//activityName启动activity的第二个参数
                 Intent intent=new Intent();
               intent.setComponent(new ComponentName(packageName, activityName));
                 startActivity(intent);

你可能感兴趣的:(packageinfo,packagemanager,activities)