2011-07-15 75 views
0

我的程序運行良好,但突然NETWORK_PROVIDER停止提供位置更新。 如果啓用WIFI,它也不起作用。 有人知道爲什麼嗎?NETWORK_PROVIDER未提供位置更新

謝謝!

下面是一些(crypled)的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> 
+0

你有沒有嘗試它在實際設備上?我不確定您是否可以在模擬器上實現NETWORK_PROVIDER服務... –

+0

是的,我在兩個不同的設備上嘗試過它,我都沒有在兩個工作 – nomoral

+0

檢查isLocationProviderEnabled(LocationManager.NETWORK_PROVIDER)? –

回答

1

爲了確保如果NETWORK_PROVIDER是這樣的操作檢查,

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