单击按钮直接打开 StreetView 应用程序 - android

Open StreetView App directly on button click- android

我想直接从我的应用程序打开 Google 街景视图 Android。 谁能帮我做这件事?

感谢 SO,我已经使用 Streeview 成功打开了地图应用程序,但这不是我想要的。

我真的想直接从我的应用程序打开街景相机,这样我就可以拍全景照片了。

我的实际任务是开发一个可以拍摄全景图像的相机应用程序,但我找不到任何东西,所以我正在研究可以做的事情而不是像纸板这样的相机应用程序。 这是我之前提出的问题的 link- App to capture 360 View android

请帮忙解决这个问题!

您可以通过PackageManager class:

获取启动意图
PackageManager pm = context.getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage("com.google.android.street");
context.startActivity(launchIntent);

请注意,如果找不到包,getLaunchIntentForPackagereturns null。 所以你可能想添加一个空检查:

if (launchIntent != null) {
        context.startActivity(launchIntent);
    } else {
        Toast.makeText(context, "StreetView not Installed", Toast.LENGTH_SHORT).show();
        launchPlayStore(mContext,com.google.android.street);
    }

您可以使用以下代码导航他通过 Play 商店安装 StreetView 应用程序

public void launchPlayStore(Context context, String packageName) {
    Intent intent = null;
    try {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id=" + packageName));
            context.startActivity(intent);
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
        }
    }

您也可以使用以下代码打开街景相机,点击我的应用程序中的全景图像

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.street", "com.google.android.street.CameraActivity")); 
//provided you should know the camera activity name 
startActivity(intent);

此外,您可能需要将 android:exported="true" 添加到 Activity 的 manifest 中,您从中调用上述代码。

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.google.android.street"));
context.startActivity(intent);

@Rajat 你可以使用上面的代码将用户重定向到 Google Street View 播放商店页面。