【问题标题】:Open StreetView App directly on button click- android [closed]直接在按钮单击上打开 StreetView 应用程序 - android [关闭]
【发布时间】:2018-03-14 11:06:28
【问题描述】:

我想直接从我的应用打开 Google Street View Android。 谁能帮我做这件事?

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

我实际上想直接从我的应用程序中打开街景相机,以便拍摄全景照片。

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

请帮忙!

【问题讨论】:

  • 我已经试过了,它会用街景打开地图应用,我想打开谷歌街景应用,而不是地图。但是感谢您的快速回答。
  • 查看我下面的答案

标签: android google-street-view google-streetview-publish


【解决方案1】:

您可以通过PackageManager 类获取启动意图:

PackageManager pm = context.getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage("com.google.android.street");
context.startActivity(launchIntent);

请注意,如果找不到包,getLaunchIntentForPackage 将返回 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" 添加到您从中调用上述代码的活动的manifest

【讨论】:

  • 谢谢,伙计,它就像魅力一样!你能帮我做一件事吗?如果没有安装 Streetview,我想让用户去玩商店?或一些我可以了解更多关于使用街景的链接实际上我想直接打开街景相机以从我的应用程序中单击全景图像。同时,我接受你的回答。谢谢
  • 如果没有安装 StreetView,您可以通过 intent 轻松导航用户玩商店,还可以打开相机 Activity 以点击图片,也可以尝试通过 Intent 搜索打开的自定义 Activity
  • 检查我编辑的答案我知道它很长,但你可以实现你想要的
  • intent.setComponent(new ComponentName("com.google.android.street", "com.google.android.street.CameraActivity"));这不行吗?应用程序崩溃 **“您是否在 AndroidManifest.xml 中声明了此活动?”**
  • 你知道除了com.google.android.street.CameraActivity之外还有什么类Activity可以调用吗?
【解决方案2】:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.google.android.street"));
context.startActivity(intent);

@Rajat 你可以使用上面的代码将用户重定向到谷歌Street View play store 页面。

【讨论】:

    猜你喜欢
    • 2014-12-22
    • 1970-01-01
    • 2017-12-03
    • 1970-01-01
    • 2016-03-23
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多