【问题标题】:How can Google's own MapsActivity result in a ClassNotFoundException on a Samsung phone?Google 自己的 MapsActivity 如何在三星手机上导致 ClassNotFoundException?
【发布时间】:2019-08-15 10:09:54
【问题描述】:

我昨天在我的 Google Play 控制台中遇到了最奇怪的错误。

我有一个按钮,可以在 Google 地图应用中打开路线。用了好几年了。看起来像这样:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                Uri.parse("http://maps.google.com/maps?f=d&daddr=" +
                    lat + "," + lon));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            activity.startActivity(intent);

昨天我收到了这个错误日志:

Samsung Galaxy J6+ (j6primelte), Android 8.1
android.content.ActivityNotFoundException: 

我无法让全世界了解这是怎么发生的,我以前从未见过。有谁比我更了解?

编辑: 显然我知道我可以在它周围放置一个 try/catch。那不是我的问题。我想知道如何在三星上获得 ActivityNotFound 在谷歌地图 API 中的某些东西上。我唯一能想到的就是有根手机?

此按钮浮动在 Google 地图上方,我们会在应用启动时检查 google play 服务,因此除非您已经在应用中看到 Google 地图,否则您无法到达这一点。

【问题讨论】:

  • 您的 Google Play 服务是最新的吗?您是否不小心禁用了它?
  • @Mathias 你的手机有谷歌地图应用吗?
  • 这意味着设备上没有安装com.google.android.apps.maps 包(谷歌地图应用程序)。是的,这是可能的。并非所有设备都默认安装它。
  • 大家好。是的,它似乎绝对没有安装。但是,每当应用程序启动时,我们都会检查是否存在 google play 服务,以及如何不将其安装在三星手机上?这基本上是困扰我的。它是地图顶部的“方向”按钮,因此除非已经显示 Google 地图,否则您甚至无法在我们的应用中到达那里!

标签: android android-activity google-maps-android-api-2 android-maps


【解决方案1】:

“能够显示 Google 地图”和“已安装 Google 地图应用”不是一回事。显然,您的用户安装了 Play 服务(用于在您的应用中嵌入地图),但没有安装 Google 地图。大概他或她已经将手机植根并安装了没有谷歌地图的不同ROM。通常(如您现在所见)假设手机上将安装哪些应用程序并不是一个好主意。

这是我检查它的代码:

public void showDirections(String address, FragmentActivity activity) {

    address = Uri.encode(address);
    Uri gmmIntentUri = Uri.parse("google.navigation:q=" + address);
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    mapIntent.setPackage("com.google.android.apps.maps");

    if (mapIntent.resolveActivity(activity.getPackageManager()) == null) {
        DialogUtils.getInstance(activity).reportError(activity, "Google Maps is required for this feature");
        return;
    }

    activity.startActivity(mapIntent);
}

【讨论】:

  • 是的,我也得出了这个结论。感谢您的回复。
【解决方案2】:

确保输入您的代码,

try {

    //Put your code here

    } catch (Exception e) {
        e.printStackTrace();
    }

因为当您设置打开特定应用程序的意图时,该应用程序可能未安装在该设备(在您的情况下是三星手机)中,因此找不到下面的 calss 并且它抛出异常。

intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

【讨论】:

    猜你喜欢
    • 2011-10-25
    • 1970-01-01
    • 2011-01-07
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 2015-01-28
    相关资源
    最近更新 更多