NETWORK_PROVIDER未提供位置更新

时间:2011-07-15 18:21:15

标签: java android geolocation locationmanager

我的计划运作良好,但突然NETWORK_PROVIDER停止提供位置更新。 如果启用了WIFI,它也不起作用。 有人知道为什么吗?

谢谢!

这是一些(加密的)Java:

package com.tripr;

public class MyWallpaperService extends WallpaperService{



    <snip>


    @Override
    public Engine onCreateEngine() {
        return new CubeEngine(this);
    }


    class CubeEngine extends Engine  implements LocationListener{

        private MyWallpaperService mws;
        private LocationManager lm;


        <snip>


        CubeEngine(MyWallpaperService mymws) {
            mws = mymws;

            lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
            requestLocationUpdates();
            MyThread myThread = new MyThread(lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
            myThread.start();
        }

    void requestLocationUpdates(){
            lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000*30, 10, this);
        }

        void removeUpdates(){
            lm.removeUpdates(this);
        }


        @Override
        public void onLocationChanged(Location location) {
            MyThread myThread = new MyThread(location);
            myThread.start();

        }

        <snip>
}

和清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tripr"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

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


  <uses-feature android:name="android.software.live_wallpaper" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <service android:name=".MyWallpaperService"
            android:label="@string/app_name"
            android:icon="@drawable/icon"
            android:permission="android.permission.BIND_WALLPAPER">

            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data android:name="android.service.wallpaper"
                android:resource="@xml/livewallpaper" />

        </service>

    </application>
</manifest>

1 个答案:

答案 0 :(得分:1)

要确保NETWORK_PROVIDER是否可以运行,请检查

if(isLocationProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
     Log.i("PROVIDER", "ENABLED");
}