【问题标题】:SecurityException when calling getLastKnownLocation调用 getLastKnownLocation 时出现 SecurityException
【发布时间】:2023-04-09 05:56:01
【问题描述】:

当用户打开调用位置管理器的 getLastKnownLocation 方法的 Activity 时,我们收到了一些设备崩溃的报告。我们已经在应用清单中请求了所有必需的权限:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

这是堆栈跟踪:

java.lang.RuntimeException: Unable to resume activity {com.projectname/com.projectname.ui.AtmFinderActivity}: java.lang.SecurityException: invalid package name: com.google.android.gms
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
        at android.app.ActivityThread.access$600(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
        at android.os.Handler.dispatchMessage(Handler.java)
        at android.os.Looper.loop(Looper.java)
        at android.app.ActivityThread.main(ActivityThread.java)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
        at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: invalid package name: com.google.android.gms
        at android.os.Parcel.readException(Parcel.java)
        at android.os.Parcel.readException(Parcel.java)
        at android.location.ILocationManager$Stub$Proxy.getLastLocation(ILocationManager.java)
        at android.location.LocationManager.getLastKnownLocation(LocationManager.java)
        at android.privacy.surrogate.PrivacyLocationManager.getLastKnownLocation(PrivacyLocationManager.java)
        at com.projectname.util.LocationUtils.getLastKnownLocation(SourceFile:48)
        at com.projectname.ui.AtmFinderFragment.initMapIfNeeded(SourceFile:401)
        at com.projectname.ui.AtmFinderFragment.onGooglePlayServicesAvailable(SourceFile:187)
        at com.projectname.maps.GoogleMapServicesUtil.getGooglePlayServicesStatus(SourceFile:40)
        at com.projectname.ui.AtmFinderFragment.onResume(SourceFile:149)
        at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:917)
        at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1080)
        at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1062)
        at android.support.v4.app.FragmentManagerImpl.dispatchResume(SourceFile:1820)
        at android.support.v4.app.FragmentActivity.onPostResume(SourceFile:412)
        at com.actionbarsherlock.app.SherlockFragmentActivity.onPostResume(SourceFile:69)
        at android.app.Activity.performResume(Activity.java)
        ... 13 more

这里是来自 LocationUtils 的相关方法:

public static Location getLastKnownLocation(Context context) {
    if (context != null) {
        LocationManager lm = (LocationManager) context.getSystemService(
                Context.LOCATION_SERVICE);

        // Get our last known location
        Location location = lm.getLastKnownLocation(
                LocationManager.NETWORK_PROVIDER);
        if (location == null) {
            location = lm.getLastKnownLocation(
                    LocationManager.GPS_PROVIDER);
        }
        return location;
    }
    return null;
}

我们无法在手头的任何设备上重现此问题。有没有人遇到过这个问题?

【问题讨论】:

  • 这只是猜测,但对我来说,这听起来像是自定义 ROM 与 Google Play 服务存在某种问题。我会进一步深入了解您遇到问题的设备,它们是什么,它们运行的​​ Android 版本是什么,它们是否有某种自定义 ROM 或其他干扰 Google Play 的自定义?
  • @CharlieCollins 同意了。我们看到的大多数出现此问题的设备都是运行 Android 4.2.2 的 Galaxy Nexus。我还没有关于他们正在运行的特定构建的任何信息。
  • 我们也看到了这个问题,看起来是因为自定义 ROM。
  • @IanG.Clifton 你能详细说明一下吗?你看到了什么让你这么想?我很想了解这些人正在使用的构建,以便我可以进行工程设计。
  • @twaddington 当我们的应用程序首次推出时,我们收到了一封来自某人的支持电子邮件,称该应用程序每次在他的自定义 4.2.2 ROM 上启动时都会崩溃。崩溃的时间和频率与该用户一致,而该崩溃就是您所看到的。不幸的是,该用户没有回复电子邮件以获取更多详细信息:(

标签: android android-location android-maps-v2


【解决方案1】:

在我看来你可以通过使用require feature 来阻止它

【讨论】:

    【解决方案2】:

    看看这个。在这里,我实现了查找最后一个已知 gps 和最后一个已知网络位置的方法。 https://github.com/thamaranga/GpsNew2/tree/master/GpsNew2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多