调用从应用程序的默认主屏幕应用程序、屏幕

2023-09-07 09:24:09 作者:去尼玛的爱情

我需要调用默认主屏幕随我的手机从我的应用程序,它也是一个主屏幕应用程序。我试图寻找和发现这个

I need to call the default home screen that comes with my phone from my application which is also a home screen app. I've tried searching and find this

    ArrayList<Intent> intentList = new ArrayList<Intent>();
    Intent intent=null;
    final PackageManager packageManager=getPackageManager();
    for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(new 
                  Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 
                                                        PackageManager.MATCH_DEFAULT_ONLY)) {
    intent=packageManager.getLaunchIntentForPackage(
                          resolveInfo.activityInfo.packageName);
    intentList.add(intent);
    }

这code正在为所有其他发射器而不是默认的启动器。我试图在code。使用破发点,并发现,在名单的0指数应该有默认的启动意图,但意图一点儿也不保存值。我是否需要某种权限 谢谢

this code is working for the all the other launchers but not for the default launcher. I tried using break points in code and found that at 0 index of list there should be default launcher intent but intent does'nt hold the value. Do I need some kind of permission thanks

推荐答案

您可以只是简单的得到ResolveInfo名称和类,并意图manualy像sonyercisson包名是com.sonyericsson.home和类是 com.sonyericsson.home.HomeActivity

you can just simple get the name and class from ResolveInfo and make intent manualy like for sonyercisson the package name is "com.sonyericsson.home" and class is "com.sonyericsson.home.HomeActivity"

   Intent intent = new Intent();
   intent.setClassName("com.sonyericsson.home", "com.sonyericsson.home.HomeActivity");
   intent.addCategory(Intent.CATEGORY_LAUNCHER);
   startActivity(intent);

它的工作原理

it works