在三星设备 (SM-J200F-sdk 22) 中调用 ACTION_VIEW (geo / map) 的意图时应用程序崩溃但适用于许多其他设备!任何解决方案?

Posted

技术标签:

【中文标题】在三星设备 (SM-J200F-sdk 22) 中调用 ACTION_VIEW (geo / map) 的意图时应用程序崩溃但适用于许多其他设备!任何解决方案?【英文标题】:in Samsung device (SM-J200F-sdk 22) app crashes when calling intent for ACTION_VIEW (geo / map) But Works on many other devices! any solution? 【发布时间】:2019-06-09 03:54:16 【问题描述】:

错误来自这行代码:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:" + mission.Customer.Lat + "," + mission.Customer.Lng)); startActivity(intent);

这是错误:

【问题讨论】:

【参考方案1】:

    没有可用于处理 geo: URI 的应用程序。将 Google Maps 等安装到设备上。

    在您的应用程序中,在启动外部活动时捕获 ActivityNotFoundException。添加某种优雅的降级,例如启动相同坐标的 Web URL 或显示错误消息。

【讨论】:

【参考方案2】:

确保在此设备中启用了谷歌地图应用程序,有时该应用程序从设备设置中禁用并导致此问题

【讨论】:

【参考方案3】:

为了避免在启动具有隐式意图的活动时发生这种崩溃。您应该使用下面的代码来验证是否存在具有符合给定条件的活动的包。更多here或here

使用 Kotlin:

if(intent.resolveActivity(packageManager) != null)
      startActivity(intent)

【讨论】:

【参考方案4】:

可以打印异常:

try 
        context.startActivity(intent);
     catch (Exception e) 
        e.printStackTrace();
    

例外情况可能是:

android.util.AndroidRuntimeException(Calling startActivity() from
outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag.
Is this really what you want?)

在这种情况下,您应该添加:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

【讨论】:

问题中显示的特定例外不是您答案中的例外。

以上是关于在三星设备 (SM-J200F-sdk 22) 中调用 ACTION_VIEW (geo / map) 的意图时应用程序崩溃但适用于许多其他设备!任何解决方案?的主要内容,如果未能解决你的问题,请参考以下文章