用类名启动Activity Android [英] Start Activity Android with class name

查看:515
本文介绍了用类名启动Activity Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Following Code to start setting I want to launch the setting activity which is started by 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);

推荐答案

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

You can use this snippet to open Settings Activity :

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

如果您不知道必须打开什么活动,可以在这里找到它的名称和包名. a>.

If you do not know what Activity you have to open,you can find it's name and it's package name as I mentioned here.

这篇关于用类名启动Activity Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆