打开默认的照片库应用程序

Open the default photo gallery app

我希望图库应用在单独的 window 中启动,而不是在我的应用中。我也不想选择图片,我只想打开默认的图库应用程序。 有些 questions 与这个非常相似,但它们都不是作为独立应用程序打开图库,而是始终在调用的应用程序内部 startActivity(intent);。 see here。这是我的名为 SM2 的应用程序。在内部,默认图库应用程序是可见的,这不是所需的行为。

如果 phone 上没有名为 'com.android.gallery' 的包,则以下代码没有用处:

           Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.gallery");
            if (launchIntent != null) {
                startActivity(launchIntent);//null pointer check in case package name was not found
            }

这会在我的应用程序中打开一个图库,不像独立任务那样:

Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(Environment.getExternalStoragePublicDirectory(
                            Environment.DIRECTORY_MOVIES)));
startActivity(intent1);

这也会在我的应用程序中打开图库:

              Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                            "content://media/internal/images/media/"));
startActivity(intent);

It is launched inside of the application

它正在您的 task 中启动。您可以在 Intent 上使用 FLAG_ACTIVITY_NEW_TASK 让它在自己的任务中启动。

I also dont want to choose a picture, I just want to open the default gallery app

欢迎您尝试 using CATEGORY_APP_GALLERY,但并非所有图库应用程序都可能有支持此功能的 activity。