【问题标题】:How to open from my app a specific activity from an other app?如何从我的应用程序打开来自其他应用程序的特定活动?
【发布时间】:2017-06-03 01:32:19
【问题描述】:

我正在开发一个应用程序,它可以通过意图打开其他应用程序并且它运行良好,但现在我需要打开一个特定的活动(或应用程序的一部分),我什至不知道它是否可能。

在这种情况下,我想从 Google Cardboard 应用程序打开街景。我无法弄清楚或找到这样做的方法。

这是我使用的意图(有效但不能完全完成任务):

public void actionOpenCardboard(View view) {
    Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.google.samples.apps.cardboarddemo");
    if (launchIntent != null) {
        startActivity(launchIntent);
    }
}

【问题讨论】:

    标签: android android-intent uri geo google-street-view


    【解决方案1】:

    您可以通过这种方式启动Activity

    Intent intent = new Intent();
    intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
    startActivity(intent);
    

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

    【讨论】:

    • 他需要从他的应用中打开 Google Cardboard 应用的街景视图。
    • 如果是 Cardboard 应用中的Activity,他可以使用它,前提是他知道应用的 Activity 名称和包名称
    【解决方案2】:

    您必须了解“Google Cardboard 应用程序”如何打开“街景”以及需要哪些参数(即当前纬度、经度、缩放级别)。

    如果你很幸运,IntentIntercept app 可以帮助你找出必要的意图细节。

    如果您只需要地图,并且地图来自“Google Cardboard 应用”或任何其他地图应用并不重要,您可以尝试使用地理 uri 的 ACTION_VIEW。

    private void onButtonClick[] {
        double lat = 52.1;
        double lon = 9.2;
        double zoom = 10;
    
        // no need for  de.k3b.geo-lib for simple request:
        String uriGeoSimple = String.format(Locale.ENGLISH, 
                    "geo:0,0?q=%f,%f&z=%f", lat, lon,zoom);
    
        // (1) GEOClientActivity creates and sends an android ACTION_VIEW intent 
        // with coordinate
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGeoSimple));
        startActivity(intent);
    }
    

    更多详情见

    如果您发现“Google Cardboard 应用”所需的意图详细信息,请随时将信息添加到https://github.com/k3b/k3b-geoHelper/wiki/Android-Geo-aware-apps

    【讨论】:

      猜你喜欢
      • 2020-03-10
      • 1970-01-01
      • 2023-01-28
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      相关资源
      最近更新 更多