getLastKnownLocation当SecurityExc

getLastKnownLocation当SecurityExc

本文介绍了调用getLastKnownLocation当SecurityException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户打开调用位置管理器的 getLastKnownLocation 方法的活动,我们已经得到了一些设备崩溃的报告。我们已经要求所有所需的权限在我们的应用程序清单:

We've been getting reports of crashes on some devices when a user opens an Activity that calls the location manager's getLastKnownLocation method. We've requested all the required permissions in our application manifest:

<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的相关方法:

Here is the relevant method from 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;
}

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

We've been unable to reproduce this issue on any device we have on hand. Has anyone encountered this problem before?

推荐答案

检查了这一点。在这里,我已经实现了最后找到知名GPS和最后一个已知的网络位置的方法。

Check this out. Here I have implemented methods for find last known gps and last known network locations.https://github.com/thamaranga/GpsNew2/tree/master/GpsNew2

这篇关于调用getLastKnownLocation当SecurityException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 20:23