12

我正在使用以下代码开始设置我想启动由 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);
4

2 回答 2

31

您可以使用此代码段打开SettingsActivity :

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

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

于 2013-08-10T10:50:51.867 回答
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
于 2014-04-16T14:26:24.540 回答