使用类名启动Android活动

时间:2013-08-10 10:14:49

标签: android android-activity classname

我正在使用以下代码开始设置我想启动由android ins启动的设置活动

PackageList allowedAppsPackageName=CallHelper.Ds.getPackageList();
            PackageManager manager = CallDetectService.packageManager;
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
        Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
        final int count = apps.size();
        ResolveInfo info=new ResolveInfo();;
        GridViewAppList.clear();

                 for (int i = 0; i < count; i++) 
                 {

                        info= apps.get(i);
                        if(info.activityInfo.applicationInfo.packageName.contains("setting"))
                            break;

                 }
                ApplicationInfo application = new ApplicationInfo();

                application.title = info.loadLabel(manager);
                application.setActivity(new ComponentName(
                        packageName,
                        info.activityInfo.name),
                        Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                application.icon = info.activityInfo.loadIcon(manager);
                application.packagename=packageName;
                Log.i("PKG", application.packagename+" "+packageName+" "+info.activityInfo.name);
                GridViewAppList.add(application);

2 个答案:

答案 0 :(得分:25)

您可以使用此代码段打开Settings活动:

Intent intent=new Intent();
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings"));
startActivity(intent);

如果你不知道你必须打开什么活动,你可以找到它的名字和它的包名,就像我提到的那样here

答案 1 :(得分:0)

Settings类中有许多动作常量可用于创建意图,该意图将为所提供的子设置启动活动,或者只是根据操作启动“设置”应用程序。

例如:

intent = new Intent(Settings.ACTION_SETTINGS); // ACTION_SETTINGS will start the Settings app

intent = new Intent(Settings.ACTION_WIFI_SETTINGS); // ACTION_WIFI_SETTINGS will show the WiFi settings